ioscocos2d-iphoneccmenuitem

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


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?


Solution

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

    -(void) unselected{
        [super unselected];
        [self myUnselectedExtension];
    }
    
    -(void) myUnselectedExtension{
        // whatever is your need , do it here.
    }