Game Development Reference
In-Depth Information
To enable the targeted touch handler, add the following method to your layer's class:
-(void) registerWithTouchDispatcher
[[CCDirector sharedDirector].touchDispatcher addTargetedDelegate:self
Caution If you leave the registerWithTouchDispatcher method
empty, you won't receive any touches at all! If you want to keep the method but
also want to use the default handler, you'll have to call [super register-
WithTouchDispatcher] in this method. It's also worth mentioning that
the registerWithTouchDispatcher method is only called in CCLayer
classes. You can also add non- CCLayer nodes as touch delegates, but in that
case you must call [[CCDirector sharedDirect-
or].touchDispatcher removeDelegate:self] at a later time.
Now, instead of using the default touch input methods, you're using a slightly different
set of methods. They're almost equivalent with the exception of receiving a
(UITouch*) touch instead of a (NSSet*) touches as the first parameter:
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {}
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event {}
What's important to note here is that ccTouchBegan returns a BOOL value. If you
return YES in that method, it means you don't want this particular touch to be propag-
ated to other targeted touch handlers with a lower priority—you have effectively “swal-
lowed” this touch.
Note Cocos2d has no built-in support for recognizing gestures, but Kobold2D
supports all gesture recognizer types via the KKInput class by writing
[KKInput sharedInput].gesturePanEnabled = YES . You can
Search Nedrilad ::

Custom Search