cocos2d event handler not fired when reentering scene
Posted
by
Adam Freund
on Game Development
See other posts from Game Development
or by Adam Freund
Published on 2012-11-25T10:20:23Z
Indexed on
2012/11/25
11:24 UTC
Read the original article
Hit count: 266
cocos2d-iphone
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]]; }
© Game Development or respective owner