cocos2d event handler not fired when reentering scene
- by Adam Freund
I am encountering a very strange problem with my cocos2d app. I add a sprite to the page and have an event handler linked to it which replaces the scene with another scene. On that page I have another button to take me back to the original scene. When I am back on the original scene, the eventHandler doesn't get fired when I click on the sprite. Below is the relevant code. Thanks for any help!
CCMenuItemImage *backBtnImg = [CCMenuItemImage
itemWithNormalImage:@"btn_back.png"
selectedImage:@"btn_back_pressed.png"
target:self
selector:@selector(backButtonTapped:)];
backBtnImg.position = ccp(45, 286);
CCMenu *backBtn = [CCMenu menuWithItems:backBtnImg, nil];
backBtn.position = CGPointZero;
[self addChild:backBtn];
EventHandler method (doesn't get called when the scene is re-entered).
(void)backButtonTapped:(id)sender {
NSLog(@"backButtonTapped\n");
CCMenuItemImage *backButton = (CCMenuItemImage *)sender;
[backButton setNormalImage:[CCSprite spriteWithFile:@"btn_back_pressed.png"]];
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade
transitionWithDuration:.25 scene:[MenuView scene] withColor:ccBLACK]];
}