CCMenuitem, CCmenu, CCMenuItemImage of my previous scene are retaining even after getting replaced to new scene

CCMenuitem, CCmenu, CCMenuItemImage of my previous scene are retaining even after getting replaced to new scene
0.0 0


I am using CCmenu, CCMenuItemImage in all of my scenes (have added as a child in different corresponding layers). Now as i replace a scene and i am in next scene… the callbacks against my previous scene’s CCMenuItemImage are invoking as i press to the area where they were placed in first scene…(they are not visible though). do anyone else has ever encounter such thing?


Anyone to help me or know what could have been the cause please?


I ll really appreciate if any input from you guys…


Please show some code. How do you create CCMenu, CCMenuItemImage, how do you add them, how do you replace scene.


Hi, thanks responding…
Here is how i am doing it…

CCMenuItemImage * hOFItem1 = CCMenuItemImage::create(“back-button.png”,“back-hover.png”, this,menu_selector(classname::BackButton));
hOFItem1~~>setPosition); // S is the screen size.
CCMenu* hOF_menu1;hOF_menu1= CCMenu::create;
hOF_menu1~~>setPosition( CCPointZero);
cclayer **achivement_layer~~>addChild;
and in the call back… that is how i am replacing my scene…

void classname::BackButton
CCScene * pScene = CCScene::create;
CCLayer * pLayer = new MenuController;// layer name
CCDirector** pDirector = CCDirector::sharedDirector();

now after i have added… if i press the area where i have added the hOFItem1 above call back is been invoked… and i have test that with other CCMenuItemImage as well, of other scenes


Not too much code :slight_smile:
Anyway, your description of the problem leads me to supposition that touch handler for your menu wasn’t removed when the scene got replaced. The removal of handlers happens in CCLayer::onExit() by default, which is recursively executed on all nodes in the scene being replaced. I see you’ve implemented your custom layer. If you’ve overriden onExit() please make sure you’re calling parent’s onExit() in it (CCLayer::onExit()). If this doesn’t help please post the code of MenuController (use tag )


Thank you so much, you are right about the problem. I wasn’t overriding onExit() in my layer and consequently wasn’t calling parent’s onExit() as well. Now that i have implemented it, its not causing this problem. Thanks for assistance :slight_smile:


You are welcome :slight_smile: You don’t need to override onExit because default onExit will do the work. But if you do (for your custom onExit behavior) you need to call parent’s onExit in it to make things work. So I don’t know what was the correct solution but glad it helped :slight_smile:


Yeah you are right about overriding parent’s onExit(). it wasn’t getting called and thus the callbacks were retaining. Thanks a lot for the help :slight_smile: