I have a CCLayer, that should be “unmasked” from top to bottom.
I implemented GLScissor pre-visit and post-visit to cut what is out of the layer bounds:
#pragma mark Clipping
-(void)visit {
[self preVisit];
[super visit];
[self postVisit];
}
-(void)preVisit {
if (!self.visible)
return;
glEnable(GL_SCISSOR_TEST);
CGRect clipRect = [self boundingBox];
CGPoint origin = [self convertToWorldSpaceAR:clipRect.origin];
CGRect scissorRect = CGRectMake(origin.x - self.anchorPoint.x * clipRect.size.width, 768 - origin.y - self.anchorPoint.y * clipRect.size.height, clipRect.size.width, clipRect.size.height);
scissorRect = CC_RECT_POINTS_TO_PIXELS(scissorRect);
glScissor((GLint) scissorRect.origin.x, (GLint) scissorRect.origin.y,
(GLint) scissorRect.size.width, (GLint) scissorRect.size.height);
}
-(void)postVisit {
glDisable(GL_SCISSOR_TEST);
}
And I make the CCLayer grow by setting a contentSize of 1024×0 and using a scheduled call:
-(void) grow {
float height = [self contentSize].height + 2;
if (height >= 768){
[self unschedule:@selector(grow)];
height = 768;
}
[self setContentSize:CGSizeMake(1024, height)];
}
This works like a charm. The CCLayer grows in height steadily and it is unmasked perfectly. However, I can’t use any of the easing functions since I’m not using any action.
Is there any action that resizes the CCLayer (not scaling) that would allow me to use easing functions or is there any other (better) way to do this?
The best candidate is to use CCActionTween (formerly: CCPropertyAction) and wrap that in an ease action:
This will modify the property named
sizeHeightof the layer. You can use that to adjust the contentSize, since you can’t tween a C struct property like CGSize or CGPoint directly: