Skip to content

Commit 2cb233e

Browse files
author
Thayer J Andrews
committed
CCEffectsTest - Add another stacking test for sprite color / opacity + effects
Leave stitching enabled on the stack but disable it after the second effect. This means our stack [A, B, C] becomes [ AB, C ] instead of [ ABC ] which is another good case to test.
1 parent a672930 commit 2cb233e

File tree

1 file changed

+65
-16
lines changed

1 file changed

+65
-16
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#import "CCEffectNode.h"
55
#import "CCEffectBlur.h"
66

7+
#import "CCEffect_Private.h"
78
#import "CCEffectStack_Private.h"
89

910
@interface CCEffectsTest : TestBase @end
@@ -677,7 +678,7 @@ -(void)setupSpriteColorTest
677678
CCLabelTTF *plainTitle = [CCLabelTTF labelWithString:@"No FX" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
678679
plainTitle.color = [CCColor blackColor];
679680
plainTitle.positionType = CCPositionTypeNormalized;
680-
plainTitle.position = ccp(0.1f, 0.7f);
681+
plainTitle.position = ccp(0.05f, 0.7f);
681682
plainTitle.horizontalAlignment = CCTextAlignmentRight;
682683

683684
[self.contentNode addChild:plainTitle];
@@ -686,36 +687,40 @@ -(void)setupSpriteColorTest
686687
CCLabelTTF *effectTitle = [CCLabelTTF labelWithString:@"FX" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
687688
effectTitle.color = [CCColor blackColor];
688689
effectTitle.positionType = CCPositionTypeNormalized;
689-
effectTitle.position = ccp(0.1f, 0.3f);
690+
effectTitle.position = ccp(0.05f, 0.3f);
690691
effectTitle.horizontalAlignment = CCTextAlignmentRight;
691692

692693
[self.contentNode addChild:effectTitle];
693694

695+
float x = 0.15f;
696+
float step = 0.1875f;
694697

695698
// Sprite with solid red
696699
{
697700
CCEffect *saturation = [CCEffectSaturation effectWithSaturation:0.0f];
698701

699702
CCSprite *plainSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
700703
plainSprite.positionType = CCPositionTypeNormalized;
701-
plainSprite.position = ccp(0.2f, 0.7f);
704+
plainSprite.position = ccp(x, 0.7f);
702705
plainSprite.color = [CCColor redColor];
703706
[self.contentNode addChild:plainSprite];
704707

705708
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
706709
effectSprite.positionType = CCPositionTypeNormalized;
707-
effectSprite.position = ccp(0.2f, 0.3f);
710+
effectSprite.position = ccp(x, 0.3f);
708711
effectSprite.color = [CCColor redColor];
709712
effectSprite.effect = saturation;
710713
[self.contentNode addChild:effectSprite];
711714

712715
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Is color preserved?" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
713716
title.color = [CCColor blackColor];
714717
title.positionType = CCPositionTypeNormalized;
715-
title.position = ccp(0.2f, 0.05f);
718+
title.position = ccp(x, 0.05f);
716719
title.horizontalAlignment = CCTextAlignmentCenter;
717720

718721
[self.contentNode addChild:title];
722+
723+
x += step;
719724
}
720725

721726

@@ -725,24 +730,26 @@ -(void)setupSpriteColorTest
725730

726731
CCSprite *plainSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
727732
plainSprite.positionType = CCPositionTypeNormalized;
728-
plainSprite.position = ccp(0.4f, 0.7f);
733+
plainSprite.position = ccp(x, 0.7f);
729734
plainSprite.opacity = 0.5f;
730735
[self.contentNode addChild:plainSprite];
731736

732737
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
733738
effectSprite.positionType = CCPositionTypeNormalized;
734-
effectSprite.position = ccp(0.4f, 0.3f);
739+
effectSprite.position = ccp(x, 0.3f);
735740
effectSprite.opacity = 0.5f;
736741
effectSprite.effect = saturation;
737742
[self.contentNode addChild:effectSprite];
738743

739744
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Opacity?" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
740745
title.color = [CCColor blackColor];
741746
title.positionType = CCPositionTypeNormalized;
742-
title.position = ccp(0.4f, 0.05f);
747+
title.position = ccp(x, 0.05f);
743748
title.horizontalAlignment = CCTextAlignmentCenter;
744749

745750
[self.contentNode addChild:title];
751+
752+
x += step;
746753
}
747754

748755

@@ -755,55 +762,97 @@ -(void)setupSpriteColorTest
755762

756763
CCSprite *plainSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
757764
plainSprite.positionType = CCPositionTypeNormalized;
758-
plainSprite.position = ccp(0.6f, 0.7f);
765+
plainSprite.position = ccp(x, 0.7f);
759766
plainSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
760767
[self.contentNode addChild:plainSprite];
761768

762769
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
763770
effectSprite.positionType = CCPositionTypeNormalized;
764-
effectSprite.position = ccp(0.6f, 0.3f);
771+
effectSprite.position = ccp(x, 0.3f);
765772
effectSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
766773
effectSprite.effect = stack;
767774
[self.contentNode addChild:effectSprite];
768775

769-
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Stack (with stitching)" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
776+
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Stack (all stitching)" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
770777
title.color = [CCColor blackColor];
771778
title.positionType = CCPositionTypeNormalized;
772-
title.position = ccp(0.6f, 0.05f);
779+
title.position = ccp(x, 0.05f);
773780
title.horizontalAlignment = CCTextAlignmentCenter;
774781

775782
[self.contentNode addChild:title];
783+
784+
x += step;
776785
}
777786

778787

779-
// Sprite with 50% transparent red and two stacked effects
788+
// Sprite with 50% transparent red and three stacked effects but stitching disabled
789+
// manually after the second effect
780790
{
781791
CCEffect *saturation = [CCEffectSaturation effectWithSaturation:0.0f];
792+
CCEffect *brightness = [CCEffectBrightness effectWithBrightness:0.0f];
782793
CCEffect *hue = [CCEffectHue effectWithHue:0.0f];
783794

795+
// Manually manipulate the brightness effect's stitch flags so it is stitched with
796+
// saturation but not with hue.
797+
brightness.stitchFlags = CCEffectFunctionStitchBefore;
798+
799+
CCEffectStack *stack = [CCEffectStack effectWithArray:@[saturation, brightness, hue]];
800+
801+
CCSprite *plainSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
802+
plainSprite.positionType = CCPositionTypeNormalized;
803+
plainSprite.position = ccp(x, 0.7f);
804+
plainSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
805+
[self.contentNode addChild:plainSprite];
806+
807+
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
808+
effectSprite.positionType = CCPositionTypeNormalized;
809+
effectSprite.position = ccp(x, 0.3f);
810+
effectSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
811+
effectSprite.effect = stack;
812+
[self.contentNode addChild:effectSprite];
813+
814+
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Stack (some stitching)" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
815+
title.color = [CCColor blackColor];
816+
title.positionType = CCPositionTypeNormalized;
817+
title.position = ccp(x, 0.05f);
818+
title.horizontalAlignment = CCTextAlignmentCenter;
819+
820+
[self.contentNode addChild:title];
821+
822+
x += step;
823+
}
824+
825+
826+
// Sprite with 50% transparent red and two stacked effects but no stitching
827+
{
828+
CCEffect *saturation = [CCEffectSaturation effectWithSaturation:0.0f];
829+
CCEffect *hue = [CCEffectHue effectWithHue:0.0f];
830+
784831
CCEffectStack *stack = [CCEffectStack effectWithArray:@[saturation, hue]];
785832
stack.stitchingEnabled = NO;
786833

787834
CCSprite *plainSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
788835
plainSprite.positionType = CCPositionTypeNormalized;
789-
plainSprite.position = ccp(0.8f, 0.7f);
836+
plainSprite.position = ccp(x, 0.7f);
790837
plainSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
791838
[self.contentNode addChild:plainSprite];
792839

793840
CCSprite *effectSprite = [CCSprite spriteWithImageNamed:@"Images/grossini.png"];
794841
effectSprite.positionType = CCPositionTypeNormalized;
795-
effectSprite.position = ccp(0.8f, 0.3f);
842+
effectSprite.position = ccp(x, 0.3f);
796843
effectSprite.color = [CCColor colorWithRed:0.5f green:0.0f blue:0.0f alpha:0.5f];
797844
effectSprite.effect = stack;
798845
[self.contentNode addChild:effectSprite];
799846

800847
CCLabelTTF *title = [CCLabelTTF labelWithString:@"Stack (no stitching)" fontName:@"HelveticaNeue-Light" fontSize:10 * [CCDirector sharedDirector].UIScaleFactor];
801848
title.color = [CCColor blackColor];
802849
title.positionType = CCPositionTypeNormalized;
803-
title.position = ccp(0.8f, 0.05f);
850+
title.position = ccp(x, 0.05f);
804851
title.horizontalAlignment = CCTextAlignmentCenter;
805852

806853
[self.contentNode addChild:title];
854+
855+
x += step;
807856
}
808857
}
809858

0 commit comments

Comments
 (0)