cocos2d-iphonereleaseccmenu

Cocos2D how to remove/release/clean up CCMenu


How can I add/remove CCMenu when the same button is clicked? I have added some code..

Thanks in advance..

CCMenu *menu;


    if (!isMenuVisible) {

           CCMenuItemSprite *item = [CCMenuItemSprite itemFromNormalSprite: .......];
           menu = [CCMenu menuWithItems:item, nil];
           [self addChild:menu];

} else {

           // [menu cleanup];/// didn't work
           // [menu removeFromParentAndCleanup:YES]; //// didnt work
           // [menu removeAllChildrenWithCleanup:YES];  //// didn't work

}

    isMenuVisible = !isMenuVisible;


}

Solution

  • you probably want to have the top line in your .h file, making the menu an iVar, to that the reference is kept in between successive executions of this code. Set menu to nil after you remove it.