How to access a CCMenuItemImage from a CCMenu
I have a CCMenu that contains a CCMenuItemImage named pauseButton and a CCMenuItemImage named playButton. I need to be able to access the pauseButton and playButton, but once I add them to the CCMenu开发者_JAVA百科 they disappear. I have set their tags and try to access them through [self getChildByTag:1], but the debugger says that nothing contains the tag. How can I access the members of the CCMenu?
What is the name of your CCMenu variable? If you code looks something like this:
CCMenu *menu = [CCMenu menuWithItems:playButton, pauseButton, nil];
Then you would access the play button or pause button with [menu getChildByTag:1]
not [self getChildByTag:1]
. Otherwise, if you make a reference to playButton
or pauseButton
as a instance variable of the class or as a property, you should be able to access then directly, even if you add them to the menu.
精彩评论