Cocos2d: how can I get a CCMenu item to call a selector once unselected?

439 views Asked by At

How can I get a CCMenu item to call a selector once unselected?

Is this even possible?

when adding a CCMenuItem I can specify as selector a function which will be called on button activation. What I would like is to be able to call a function once a button is not "selected" anymore (I mean selected and not activated).

I guess I have to override some methods but not sure which one :).

Any suggestion?

2

There are 2 answers

0
YvesLeBorg On BEST ANSWER

Subclass CCMenuItemWhatever and override one method (derived from CCMenuItem) :

-(void) unselected{
    [super unselected];
    [self myUnselectedExtension];
}

-(void) myUnselectedExtension{
    // whatever is your need , do it here.
}
1
CodeSmile On

It's not possible without modifying CCMenu.

You can however run a scheduled update and check each selected property of the menu items, and observe any changes from the previous selected status (stored in an ivar for example).