Skip to content

Commit f9b7c6b

Browse files
author
Thayer J Andrews
committed
CCEffectsTest - Add a test of clipping combined with effects
A clipping node renders into an effect node with an attached pixellate effect.
1 parent 3ecb865 commit f9b7c6b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,41 @@ -(void)setupSpriteColorTest
856856
}
857857
}
858858

859+
-(void)setupClipWithEffectsTest
860+
{
861+
self.subTitle = @"Clipping + Effects Test.";
862+
863+
CGSize size = [CCDirector sharedDirector].designSize;
864+
865+
CCNodeGradient *grad = [CCNodeGradient nodeWithColor:[CCColor redColor] fadingTo:[CCColor blueColor] alongVector:ccp(1, 0)];
866+
867+
CCNode *stencil = [CCSprite spriteWithImageNamed:@"Sprites/grossini.png"];
868+
stencil.position = ccp(size.width/2, size.height/2);
869+
stencil.scale = 4.0;
870+
[stencil runAction:[CCActionRepeatForever actionWithAction:[CCActionRotateBy actionWithDuration:1.0 angle:90.0]]];
871+
872+
CCClippingNode *clip = [CCClippingNode clippingNodeWithStencil:stencil];
873+
clip.alphaThreshold = 0.5;
874+
875+
CCEffectNode* parent = [CCEffectNode effectNodeWithWidth:size.width height:size.height pixelFormat:CCTexturePixelFormat_RGBA8888 depthStencilFormat:GL_DEPTH24_STENCIL8];
876+
parent.clearFlags = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
877+
parent.clearColor = [CCColor blackColor];
878+
parent.clearDepth = 1.0;
879+
parent.clearStencil = 0;
880+
parent.contentSizeType = CCSizeTypeNormalized;
881+
parent.contentSize = CGSizeMake(1.0f, 1.0f);
882+
parent.anchorPoint = ccp(0.5f, 0.5f);
883+
parent.positionType = CCPositionTypeNormalized;
884+
parent.position = ccp(0.5f, 0.5f);
885+
886+
CCEffectPixellate *effect = [CCEffectStack effectWithArray:@[[CCEffectPixellate effectWithBlockSize:4.0f], [CCEffectSaturation effectWithSaturation:1.0f]]];
887+
parent.effect = effect;
888+
889+
[clip addChild:grad];
890+
[parent addChild:clip];
891+
[self.contentNode addChild:parent];
892+
}
893+
859894
-(void)setupEffectNodeAnchorTest
860895
{
861896
self.subTitle = @"Effect Node Anchor Point Test\nTransparent RGB quads from lower-left to upper-right.";

0 commit comments

Comments
 (0)