I am trying to get the swiping to work for Cocos2d latest version here is my code:
-(void) setupGestureRecognizers
{
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeLeft setNumberOfTouchesRequired:1];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:swipeLeft];
}
It does not detect the swipe at all!
UPDATE 1:
I updated the code to the following and still no swipes are detected.
-(void) setupGestureRecognizers
{
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeLeft setNumberOfTouchesRequired:1];
[[[[CCDirector sharedDirector] openGLView] window] setUserInteractionEnabled:YES];
[[[CCDirector sharedDirector] openGLView] setUserInteractionEnabled:YES];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:swipeLeft];
}
I’ve tried to make this work as well but I’ve found an easier and also better to control method.
so for example if you wanted to detect a swipe to the left I’d so following.
Declare two variables in the interface of you’re class
In the init method of the implementation of your class enable touches
3.Add these methods to your class
the method “doStuff” is whats called if a left swipe has occurred.