cocos2d: Layer That Swallows Touches
August 12th, 2010
So you want to add a layer with a few buttons and you don’t want to propagate the touches to the layers below.
Easy, just stick the following in your layer to enable “swallow touches”.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
- (void)onEnter { [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES]; [super onEnter]; } - (void)onExit { [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; [super onExit]; } - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { return YES; } |
