-
Notifications
You must be signed in to change notification settings - Fork 59
CCGestureRecognizer
CCGestureRecognizer is an abstract base class for gesture recognizer classes.
The subclasses of CCGestureRecognizer are the following:
- CCLongPressGestureRecognizer
- CCPanGestureRecognizer
- CCPinchGestureRecognizer
- CCSwipeGestureRecognizer
- CCTapGestureRecognizer
The frame of the CCNode object (CCSprite, CCLayer, etc.) on which a gesture recognizer is added that's the space where the gesture recognizer is available. So if you add a gesture recognizer on a "full-screen" CCLayer you will be able to recognize the gesture everywhere on the screen. This is a great feature when you need to recognize gestures on specific parts of the screen.
When a gesture is recognized, your specified method gets called. You can set the method which you want to be called by the following way:
myGesture->setTarget(this, callfuncO_selector(HelloWorld::didRecognizeGesture));
The targeted method must have 1 parameter of CCObject* type and return void:
void didRecognizeGesture(CCObject * obj);
The received parameter type it's different in every case. For example, for the swipe gesture it's a CCSwipe object, for tap gesture it's a CCTap, and so on. So don't forget to cast correctly before starting to use it:
CCSwipe * swipe = (CCSwipe*)obj;
By default, when a gesture is recognized the touch propagates to other nodes below him, but you can stop the touch propagation setting the following property to true:
myGesture->setCancelsTouchesInView(true);