For detecting shake in a cocos2D program copy these lines to your layer class
bool shaked_once; //default false self.isAccelerometerEnabled = YES; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60]; shaked_once = false;
Then copy this function to the same file…. and you are done……..
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { float THRESHOLD = 2; if (acceleration.x > THRESHOLD || acceleration.x < -THRESHOLD || acceleration.y > THRESHOLD || acceleration.y < -THRESHOLD || acceleration.z > THRESHOLD || acceleration.z < -THRESHOLD) { if (!shaked_once) { shaked_once = true; } } else { shaked_once = false; } }