How to add a shake gesture in Cocos2d CCLayer?

I tried using a shaking gesture recognition system to detect a shaking gesture. I also tried to implement the code suggested by Geeky Lemon . But I can't handle the shake gesture. Is there a way to recognize a shake gesture?

Thank!

EDIT 1:

The code is executed using a demo program to demonstrate hard gesture recognition.

in 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");   
    } 
}
+5
source share
2 answers

Create your gesture recognizer in the usual way, and then add it like this:

[[[CCDirector sharedDirector] view] addGestureRecognizer:shakeGesture];
+1
source

ShakeEnabledUIWindow UIWindow. AppDelegate , ,

#import "ShakeEnabledUIWindow.h"

ShakeEnabledUIWindow

@property (strong, nonatomic) ShakeEnabledUIWindow *window;

. Shake Gesture.

0

All Articles