简体   繁体   中英

Not sure how to use ccTouchesBegan to do what I want it to do

So when I see ccTouchesBegan (or touchesBegan for that fact of the matter) I see something like this usually:

- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
   UITouch* touch = [touches anyObject];
}

But, what I am not getting is how do you just detect if one object has been touched? For example how would I check if a specific CCSprite I declared has been touched?

Sorry if this is a newbish question but, I just don't understand and if you need more clarification just ask how I can clarify myself more.

I'm not familiar with cocoas2d but in the standard API it sends the touches first to the view touched and then up the view responder chain to a view that has a controller. If that controller does not handle the touch then it goes up to the next view until it ends up at the Window object.

See Responder Objects in the Responder Chain

The best place to trap touches for specific objects is in the object themselves. In the case of sprite-like view, the sprite itself most likely needs to respond to the touch eg by moving itself. If you need the touch to be communicated to another object, you should use the delegate pattern so that the sprite can tell its delegate how its been touched.

That last sentence sounded weird.

我前面没有样品,但Cocos2D下载包中应该有一个示例,该示例演示了触摸事件及其如何传播到精灵。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM