CCMenuItem doesn't respond subclassing and adding cctouch methods to CCMenu

527 Views Asked by At

I'm making a menu, and I want one of the buttons to respond when user touch it down, so I made a subclass of CCMenu in order to add cctouchbegan method And manage it there. The problem is that I can make it to respond both things (menuItem & cctouch), is this normal? is there a way to force it to do both things? Thank you in advance, let me know if you need me to put some of the code here

2

There are 2 best solutions below

0
On BEST ANSWER

You should look at CCMenu.m -- it already implements ccTouchBegan and sets a selected flag on CCMenuItems. Your approach is probably not working because you're stealing the messages from your parent class.

Your subclass should call [super ccTouchBegan...] first, then check the selected state of the CCMenuItems to determine which button to change visually.


EDIT: Or, even easier! -- Subclass the appropriate CCMenuItem subclass (e.g. CCMenuItemSprite) and overload the selected method from it's default to include your visual alterations:

-(void) selected
{
    [super selected];
    //call method to update visuals here
}
3
On

You can simple create your own CCLayer subclass, set it's isTouchEnabled property to YES and implement any touch logic you want