Question

I have a CCMenu with a series of button added with the code:

_viewMenu = [[CCMenu alloc] init];
    for (int i = 0; i < _somearray.count; i++)
    {
        switchViewMI = [CCMenuItemImage itemWithNormalImage: [_somearray objectAtIndex:i]
                                                 selectedImage: [_somearray objectAtIndex:i]
                                                        target: self
                                                      selector: @selector(switchViewSelected:)];
        switchViewMI.tag = i;
        [_viewMenu addChild:switchViewMI];
    }

Which I use switchViewMI.tag to identify the function to call.

My question is at a point I want to delete some buttons dynamically, so I have to edit the tag. But I am not sure how to access _viewMenu.item. How can I achieve that?

Was it helpful?

Solution

with cocos2d v2.1, you can access the menu items with

[_viewMenu.children objectAtIndex:i];

careful if you iterate children and try to delete at the same time, you will get an exception. If you dont plan to animate the buttons 'disappearing', i would simply remove all menu items from the menu and rerun the logic from scratch for adding and placing them in position.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top