Tuesday, 15 June 2010

ios - cocos2d 3.x how to handle touches outside a sprite -



ios - cocos2d 3.x how to handle touches outside a sprite -

i need handle touch outside sprite. i.e. when touch outside sprite, touchbegan method of sprite still needs called. how can it?

notice using 3.x version, cctargetedtouchdelegate priority not exist anymore.

what suggest manually create public method cctouchbegan returns whether touch swallowed (just cocos2d 2.0)

in canvas:

- (void)touchbegan:(uitouch *)touch withevent:(uievent *)event { bool swallowed = no; (id kid in _childnodes) { if ([child cctouchbegan:touch event:event]) { swallowed = yes; } } if (swallowed) { return; } //continue canvas touch handler }

and in sprite:

- (bool)cctouchbegan:(uitouch *)touch event:(uievent *)event { //same usage cocos2d 2.x } //and in touch callback - (void)touchbegan:(uitouch *)touch withevent:(uievent *)event { if ([self cctouchbegan:touch event:event]) { //swallow } else { //do not swallow, pass touch [super touchbegan:touch withevent:event]; } }

ios iphone cocos2d-iphone

No comments:

Post a Comment