Cc.Menu / cc.MenuItemImage remain touchable after replaceScene

Cc.Menu / cc.MenuItemImage remain touchable after replaceScene
0.0 0


Not sure if this is a bug or intended as I haven’t worked with cocos2d before, but I have a scene with a layer that has a menu in it (with 2 MenuItemImages). One of the items triggers a change of scene via replaceScene(newScene). The new scene loads up, the images disappear, but if I click where the images were on the previous scene methods from the previous layer continue to fire.

Am I expecting too much clean-up to be done for me, and I need to hook scene onExit functions and clean up my layers myself?




Thanks for feedback.

Which version of engine did you use?

Could you please show me some sample code to reproduce the bug?


I’m using cosos2d-html5 version 2.1.1.

I’ve changed the code a bit since I posted, but general flow of the program was

The behavior I saw was that once the new scene (playScene) started, all sprites were removed (Login/Register menu items disappeared), but I could still click them (register function was firing).

For now I just added;
to onExit of the layer


This behavior is reproducible in Tests too.

For Example, I am running Cocos2d-html5-v2.1

Steps to reproduce:

  1. From main menu Choose ChipMunk Test. Do not click next, restart or prev menu items. Go back to main menu.
  2. From main menu of tests, choose click and move test.
  3. Click at bottom, where menu items prev,restart and next of ChipMunk Test are located. Now nothing abnormal happens. Next goto Main Menu.
  4. Repeat Steps 1,2,3 but this time in Step 1 Click next and loop through all tests atleast once.

After doing this, in Step 3, you will observe that clicking at the bottom of Click and Move Test takes you to either next,prev or restart callback of ChipMunk Test.
ie as described by John in opening post, the images associated with menu items have been cleared, but menu item of ChipMunk Test, is still (ghost) active.

I tried adding onExit, removeChildByTag(1) in ChipMunkBaseLayer class in ChipMunkTest.js, but this did not remove the ghost menu items, which were added with same tag.
I do not understand why only looping through all chipmunk tests atleast once, is triggering this. Or maybe there are more ways to trigger this behavior as noted by John.

Not only Click and Move, Current Language Test, also displays this behavior.
I think this because replaceScene does not completely remove earlier scene, instead just does a logical pop to newscene (CCDirector.js)

Update: Tested and reproduced same behavior on latest version 2.1.3, which mentioned bugfix on CCNode leaks in release notes.

Is it not a bug, since it is not logged in the bug/issue tracker?


Thanks for feedback again. I will check it tomorrow morning.

If it can be reproduced, I will create an issue to track it. Thanks.


Thanks Shun, It is definitely reproducible in ChipMunk Test as of v2.1.3, as noted above.

Also I have noticed other tests from v2.1 have been rewritten slightly differently in v2.1.3. This has reduced the ghost menu item residual effect in other tests.

I think there is a best practise to avoid this bug, which may have influenced the rewriting of tests in v2.1.3. Please notify what exactly is best practise to avoid this bug and

why ChipMunk Test still retains this bug.


Thanks S G, issue 2148 has been created to track this bug.


It has been fixed, please pull it from tests repo.


Thanks, the different style of Chipmunk javascript objects added to the confusion.

Turns out, it was a simple case of missing onExit call ie;