I'm currently building a game with cocos2d and I have the following Problem: I have a MenuScene, where the user can start the game. When he does so, the gestureRecognizer gets initialized with the level in the following way:
CCScene *scene = [LevelScene scene];
LevelScene *layer = (LevelScene *) [scene.children objectAtIndex:0];
UIPanGestureRecognizer *gestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePanFrom:)] autorelease];
Everything works fine, and after the level is finished, the user sees a gameOverScene and is sent back to the MenuScene. When I start the game again, everything works (ingame animations, level is displayed, etc.) besides the fact, that the gestureRecognizer isn't recognizing any touches anymore. Do you have any idea why that might be or how to debug this?
Thanks.
In all likelihood the gestureRecognizer retains the target. I've ran into a similar problem which caused the "target" scene that was a delegate of a UIKit class not to be deallocated. Ie the entire scene was leaked.
Due to some unfortunate circumstances the original scene's selector still got called but wasn't processed because the scene was forever locked in a "game over" state. My guess is that something like that is happening to you.
Question: do you relese the gestureRecognizer before changing from the LevelScene to another scene? If not, you absolutely should fix that!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With