Changing the selector of a CCMenuItem

554 Views Asked by At

Is it possible to reassign the selector of a CCMenuItem once it's been created?

I'm looking to do something like this:

//Initialization:
_menuItem =[CCMenuItemSprite itemWithNormalSprite:normalSprite
selectedSprite:selectedSprite target:self selector:@selector(nextPage:)];

//Later
_menuItem.selector = @selector(mainMenu:);

Is this possible? I couldn't find anything about it in the CCMenuItem documentation. I admit I'm not all that clear on how selectors actually work in obj-c.

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, you can use -setTarget:selector:

[item setTarget:self selector:@selector(mainMenu:)];

It is in the documentation, http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_menu_item.html#a58d8f2c72697ea34cf1e10b82cac81ff