如何在cocos2d中检测触摸? [英] How can I detect touch in cocos2d?
本文介绍了如何在cocos2d中检测触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用cocos2d为iPhone开发第二代游戏。
I am developing a 2d game for iPhone by using cocos2d.
我在游戏中使用了许多小精灵(图片)。我想触摸两个类似的精灵(图像),然后两个精灵(图像)将被隐藏。
I use many small sprite (image) in my game. I want to touch two similar types of sprite(image) and then both sprite(image) will be hidden.
如何检测特定精灵(图片)中的触摸?
How can I detect touch in a specific sprite(image) ?
推荐答案
在包含您的sprite的图层中,您需要说:
In your layer that contains your sprite, you need to say:
self.isTouchEnabled = YES;
那么你可以使用你在UIView中使用的相同的事件,有很多不同:
then you can use the same events that you would use in a UIView, but they're named a little differently:
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
//in your touchesEnded event, you would want to see if you touched
//down and then up inside the same place, and do your logic there.
}
这篇关于如何在cocos2d中检测触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文