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
Asked
Active
Viewed 511 times
2 Answers
1
You should look at CCMenu.m
-- it already implements ccTouchBegan
and sets a selected flag on CCMenuItem
s. 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 CCMenuItem
s 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
}

MechEthan
- 5,703
- 1
- 35
- 30
0
You can simple create your own CCLayer subclass, set it's isTouchEnabled property to YES and implement any touch logic you want

Morion
- 10,495
- 1
- 24
- 33
-
This is my second option, the issue here is that, the layer is already touchable, & that's why I would like to manage from the menu – Oscar May 29 '12 at 11:59
-
CCMenu is hust CCLayer subclass with implemented CCTargetedTouchDelegate methods – Morion May 29 '12 at 12:07
-
Actually I tried, & it didn't work, it's happening the same issue (or button or ccTouchBegan, never both) I finally made it work 'faking' the button as a CCSprite & then, implementing the ccTouchBegan & calling the method from there – Oscar May 29 '12 at 12:28