Skip to content

CCSwipeGestureRecognizer

Valentin-Costel Hăloiu edited this page Sep 21, 2013 · 12 revisions

CCSwipeGestureRecognizer is a subclass of CCGestureRecognizer that looks for swiping gestures in one or more directions. A swipe is a discrete gesture, and thus the associated action method is called only once per gesture.

Properties

//the permitted direction(s) of the swipe for this gesture recognizer.
int direction;

Example

CCSwipeGestureRecognizer * swipe = CCSwipeGestureRecognizer::create();
swipe->setTarget(this, callfuncO_selector(HelloWorld::didSwipe));
swipe->setDirection(kSwipeGestureRecognizerDirectionRight | kSwipeGestureRecognizerDirectionLeft);
swipe->setCancelsTouchesInView(true);
this->addChild(swipe);

CCSwipe

The CCSwipe object that you receive after a successful swipe recognition, contains the following public members:

//direction of the swipe gesture that fired the target method
//NOTE: it doesn't matter how many directions you set when creating the gesture recognizer,
//you will receive the first one which was confirmed as a swipe gesture
CCSwipeGestureRecognizerDirection direction;

//the initial location where the swipe started
CCPoint location;

CCSwipeGestureRecognizerDirection

  1. kSwipeGestureRecognizerDirectionRight
  2. kSwipeGestureRecognizerDirectionLeft
  3. kSwipeGestureRecognizerDirectionUp
  4. kSwipeGestureRecognizerDirectionDown