0
votes

i have a CCLayer class on top of which i am adding another CClayer object from another class. But i want to add the CCLayer object with a frame only while it gets added to the whole screen and i am not able to get touches seprately for the layer beneath and nor the added layer. how can i add cclayer object with a certain frame??

2

2 Answers

0
votes

Unless I'm forgetting something it should as simple as setting the isTouchEnabled flag for the layer you don't want to receive touches to NO. So something like...

CCLayer* myTopLayer;
CCLayer* myBottomLayer;

myTopLayer.isTouchEnabled = YES;
myBottomLayer.isTouchEnabled = NO;

Now only the top layer should receive touches. Another trick you can do is to scale the bottom layer to a very small value so there's no the user can touch it. Something like...

myBottomLayer.scale = 0.01f;

Then scale it back to 1.0 when you are ready.

0
votes

I dont believe you can 'frame' a layer, however you can 'frame' where the touches will be processed in the layer, something similar to :

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
    if (!visible_ || !_enabled) {
      return NO;
    }
    CGPoint loc = [touch locationInView:touch.view];
    loc = [[CCDirector sharedDirector] convertToGL:loc];

    return [self containsPoint:loc]);
}

- (BOOL) containsPoint:(CGPoint)loc {
    loc = [self convertToNodeSpace:loc];
    CGRect rect = CGRectMake('WHATEVER FRAME YOU WANT TOUCHES FOR');
    return CGRectContainsPoint(rect, loc); 
}