如何在 cocos2d 中检测触摸?如何在、cocos2d

2023-09-06 09:22:56 作者:狂霸拽酷叼

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.

使用 Cocos引擎 创建的cpp工程如何在VS中调试Cocos2d x源码

How can I detect touch in a specific sprite(image) ?

解决方案

In your layer that contains your sprite, you need to say:

self.isTouchEnabled = YES;

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.
}

 
精彩推荐
图片推荐