Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I add Shake Gesture in Cocos2d CCLayer?

I've tried using shake Gesture Recognition wrapper to detect the shake gesture. I've also tried to implement the code suggested in the Geeky Lemon. But I am unable to handle the shake gesture. Is there any way to get the shake gesture recognized?

Thank you!

EDIT 1:

The code is done by the help of the shake Gesture Recognition wrapper demo.

in the init method

ShakeDispatcher * dispatcher = [ShakeDispatcher sharedInstance];
[dispatcher addShakeListener:self];    
[[[CCDirector sharedDirector]view] addGestureRecognizer:dispatcher];

-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {  
    if ( event.subtype == UIEventSubtypeMotionShake ){      
        NSLog(@"Shake detected");   
    } 
}
like image 400
Marine Avatar asked Nov 12 '22 23:11

Marine


1 Answers

Create your gesture recogniser the normal way and then add it like so

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];
like image 103
Ben Trengrove Avatar answered Dec 10 '22 01:12

Ben Trengrove