i have created two color layers and displayed them on the screen:
if( (self=[super init] )) {
self.isTouchEnabled = YES;
CGSize s = [[CCDirector sharedDirector] winSize];
CCLayerColor* layer1 = [CCLayerColor layerWithColor: ccc4(255, 255, 0, 80)
width: 100
height: 300];
layer1.position = ccp(s.width/3, s.height/2);
layer1.isRelativeAnchorPoint = YES;
[self addChild: layer1 z:1];
CCLayerColor* layer2 = [CCLayerColor layerWithColor: ccc4(0, 0, 255, 255)
width: 100
height: 300];
layer2.position = ccp((s.width/3)*2, s.height/2);
layer2.isRelativeAnchorPoint = YES;
[self addChild: layer2 z:1];
}
return self;
}
i want to to enable touches for each layer, layer 1 and layer 2, for example if the user touches layer 1 (do something) and if you touch layer 2 (do something else). i have set up the touch dispatcher,
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:No swallowsTouches:YES];
}
after that i dont know what to do, i tried to search the cocos2d documentation and couldnt find anything thanks!
If you want them to both be registered with touch dispatcher, you will need to subclass them and add the
registerWithtouchDispatcherto each subclass directly, then use the subclasses in your master layer or scene.This is also how you register individual sprites with their own touches if you don’t want the layer to manage the touches for all its sprites.
When doing this, you will want to set different priorities so the most important layer has a chance to respond to a touch before the other layer, so you don’t get the same touch processed by multiple layers.