Question

I have 2 CCLayers stacked on top of each other; both are touch enabled. I want the top CCLayer to respond to and consume touches and the bottom layer to not react to the touches that the top layer consumes.

The top layer has a CCTouchBegan method that looks like this:

- (BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    NSLog(@"touched!");

    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    //DO STUFF WITH TOUCH

    return YES;
}

The bottom layer has a CCTouchesEnded method that looks like this:

- (void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //choose one of the touches to work with
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:[touch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];

    //DO STUFF WITH THE TOUCH
}

The result is that the top layer does not consume the touches or even respond to them at all. Only the bottom layer responds to the touches.

Was it helpful?

Solution

in your first layer you use method from CCTargetedTouchDelegate. CCLayer register self as CCStandardTouchDelegate. That's why your second layer responds to the touches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top