0
votes

I am developing a cocos2d game where I have a CCLayer named GamePlaylayer and another CCLayer named ShopLayer. ShopLayer is a fullscreen layer. GamePlayLayer is touchenabled and has multiple buttons (CCMenuItemImage). ShopLayer is accessed from a shop button which has the following @selector.

  (void) onClickShop {   
     ShopLayer * shop = [[ShopLayer alloc] init];
     [self addChild:shop z:40]; }

To stop touch propagation I used CCTouchOneByOneDelegate and the following methods in the ShopLayer.

(void) onEnter {
     [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self
                                                               priority:0 swallowsTouches:YES];
     [super onEnter];
}

(void) onExit {
     [[[CCDirector sharedDirector] touchDispatcher] removeDelegate:self];

     [super onExit];
}

(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
     return YES;
}

Now it stops ccTouchesBegan of the GamePlayLayer to be called which is fine. But it cannot stop other buttons of the GamePlayLayer to be called. So when I touch at positions where the buttons of GamePlayLayer are placed, they get called even though I can not see them.

So my question is how to stop clicking buttons of lower layer from upper layer?

2

2 Answers

0
votes

use kCCMenuHandlerPriority for the touch priority

    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:kCCMenuHandlerPriority swallowsTouches:YES];
0
votes

SetTouch priority kCCMenuHandlerPriority of this class.