1
votes

i have menu with buttons when touch the Play button game go to another scene but Touch don't work there i'm write self.isToucheEnabled=YES; in init method and add in onEnter method [[CCTouchDispatcher sharedDispatcher] setDispatchEvents:YES];

but that don't work pleas help why i can enable touch

4
Provide your code. And ask your question specifically. Is your menu button not working or Your layer not responding to touch??russell
my layer not responding to touchHayk

4 Answers

2
votes

You must put the following code:

-(void) onEnter { [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; }

inside the scene you want to enable the TouchDispatcher on, then in the same scene make sure you enter this:

-(void) onExit { [[CCTouchDispatcher sharedDispatcher] removeDelegate: self]; }

and the touch should register in every scene that you have the above code in.

0
votes

This is an example of how you define a menu in cocos2d (source):

CCMenuItem *starMenuItem = [CCMenuItemImage  temFromNormalImage:@"ButtonStar.jpg" selectedImage:@"ButtonStarSel.jpg" target:self selector:@selector(starButtonTapped:)];
starMenuItem.position = ccp(60, 60);
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];

If you need more help, please provide the code that you are using to create the menu.

0
votes

You also have to add UIGestureRecognizerDelegate interface in your CCLayer in your header!

e.g.:

@interface YourScene : CCLayer <UIGestureRecognizerDelegate>  {
     }
0
votes

In the layer use:

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

Not:

-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event