@@ -39,8 +39,8 @@ -(void)setupRefractionEffectTest
39
39
planet.position = p2;
40
40
41
41
[planet runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
42
- [CCActionMoveTo actionWithDuration: 4.0 position: ccp (p1.x, p1.y)],
43
- [CCActionMoveTo actionWithDuration: 4.0 position: ccp (p2.x, p2.y)],
42
+ [CCActionMoveTo actionWithDuration: 4.0 position: ccp (p1.x, p1.y)],
43
+ [CCActionMoveTo actionWithDuration: 4.0 position: ccp (p2.x, p2.y)],
44
44
nil
45
45
]]];
46
46
@@ -57,13 +57,16 @@ -(void)setupRefractionEffectTest
57
57
58
58
[self .contentNode addChild: renderTexture];
59
59
60
-
61
- CCTexture *sphereNormalMap = [CCTexture textureWithFile: @" Images/sphere-normal-256.png" ];
62
- CCEffect *sphereRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite normalMap: sphereNormalMap];
60
+ NSString *sphereTextureFile = @" Images/sphere-256.png" ;
61
+ CCTexture *sphereTexture = [CCTexture textureWithFile: sphereTextureFile];
62
+ CCSpriteFrame *sphereNormalMap = [CCSpriteFrame frameWithImageNamed: @" Images/sphere-normal-256.png" ];
63
+ CCEffectRefraction *sphereRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite normalMap: nil ];
63
64
64
65
p1 = CGPointMake (0 .1f , 0 .8f );
65
66
p2 = CGPointMake (0 .35f , 0 .2f );
66
- CCSprite *sprite1 = [self spriteWithEffects: @[sphereRefraction] image: @" Images/blocks-hd.png" atPosition: p1];
67
+ CCSprite *sprite1 = [self spriteWithEffects: @[sphereRefraction] image: sphereTextureFile atPosition: p1];
68
+ sprite1.normalMapSpriteFrame = sphereNormalMap;
69
+ sprite1.scale = 0 .5f ;
67
70
[sprite1 runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
68
71
[CCActionMoveTo actionWithDuration: 2.0 position: ccp (p1.x, p2.y)],
69
72
[CCActionMoveTo actionWithDuration: 1.0 position: ccp (p2.x, p2.y)],
@@ -72,14 +75,16 @@ -(void)setupRefractionEffectTest
72
75
nil
73
76
]]];
74
77
[self .contentNode addChild: sprite1];
75
-
76
-
77
- CCTexture *torusNormalMap = [CCTexture textureWithFile: @" Images/torus-normal-256.png" ];
78
- CCEffect *torusRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite normalMap: torusNormalMap];
78
+
79
+ NSString *torusTextureFile = @" Images/torus-256.png" ;
80
+ CCTexture *torusTexture = [CCTexture textureWithFile: torusTextureFile];
81
+ CCSpriteFrame *torusNormalMap = [CCSpriteFrame frameWithImageNamed: @" Images/torus-normal-256.png" ];
82
+ CCEffectRefraction *torusRefraction = [[CCEffectRefraction alloc ] initWithRefraction: 0 .1f environment: renderTexture.sprite normalMap: torusNormalMap];
79
83
80
84
p1 = CGPointMake (0 .65f , 0 .2f );
81
85
p2 = CGPointMake (0 .9f , 0 .8f );
82
- CCSprite *sprite2 = [self spriteWithEffects: @[torusRefraction] image: @" Images/blocks-hd.png" atPosition: p1];
86
+ CCSprite *sprite2 = [self spriteWithEffects: @[torusRefraction] image: torusTextureFile atPosition: p1];
87
+ sprite2.scale = 0 .5f ;
83
88
[sprite2 runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
84
89
[CCActionMoveTo actionWithDuration: 2.0 position: ccp (p1.x, p2.y)],
85
90
[CCActionMoveTo actionWithDuration: 2.0 position: ccp (p2.x, p2.y)],
@@ -88,6 +93,89 @@ -(void)setupRefractionEffectTest
88
93
nil
89
94
]]];
90
95
[self .contentNode addChild: sprite2];
96
+
97
+ __block NSUInteger spriteConfig = 0 ;
98
+
99
+ CCActionCallBlock *blockAction = [CCActionCallBlock actionWithBlock: ^{
100
+ spriteConfig++;
101
+ if (spriteConfig > 8 )
102
+ {
103
+ spriteConfig = 0 ;
104
+ }
105
+
106
+ switch (spriteConfig)
107
+ {
108
+ case 0 :
109
+ sprite1.normalMapSpriteFrame = nil ;
110
+ sphereRefraction.normalMap = nil ;
111
+ sprite1.texture = [CCTexture none ];
112
+
113
+ NSLog (@" Sprite: nil Effect: nil - You should see a rectangle." );
114
+ break ;
115
+ case 1 :
116
+ sprite1.normalMapSpriteFrame = sphereNormalMap;
117
+ sphereRefraction.normalMap = nil ;
118
+ sprite1.texture = sphereTexture;
119
+
120
+ NSLog (@" Sprite: Sphere Effect: nil - You should see a sphere." );
121
+ break ;
122
+ case 2 :
123
+ sprite1.normalMapSpriteFrame = torusNormalMap;
124
+ sphereRefraction.normalMap = nil ;
125
+ sprite1.texture = torusTexture;
126
+
127
+ NSLog (@" Sprite: Torus Effect: nil - You should see a torus." );
128
+ break ;
129
+ case 3 :
130
+ sprite1.normalMapSpriteFrame = nil ;
131
+ sphereRefraction.normalMap = sphereNormalMap;
132
+ sprite1.texture = sphereTexture;
133
+
134
+ NSLog (@" Sprite: nil Effect: Sphere - You should see a sphere." );
135
+ break ;
136
+ case 4 :
137
+ sprite1.normalMapSpriteFrame = sphereNormalMap;
138
+ sphereRefraction.normalMap = sphereNormalMap;
139
+ sprite1.texture = sphereTexture;
140
+
141
+ NSLog (@" Sprite: Sphere Effect: Sphere - You should see a sphere." );
142
+ break ;
143
+ case 5 :
144
+ sprite1.normalMapSpriteFrame = torusNormalMap;
145
+ sphereRefraction.normalMap = sphereNormalMap;
146
+ sprite1.texture = sphereTexture;
147
+
148
+ NSLog (@" Sprite: Torus Effect: Sphere - You should see a sphere." );
149
+ break ;
150
+ case 6 :
151
+ sprite1.normalMapSpriteFrame = nil ;
152
+ sphereRefraction.normalMap = torusNormalMap;
153
+ sprite1.texture = torusTexture;
154
+
155
+ NSLog (@" Sprite: nil Effect: Torus - You should see a torus." );
156
+ break ;
157
+ case 7 :
158
+ sprite1.normalMapSpriteFrame = sphereNormalMap;
159
+ sphereRefraction.normalMap = torusNormalMap;
160
+ sprite1.texture = torusTexture;
161
+
162
+ NSLog (@" Sprite: Sphere Effect: Torus - You should see a torus." );
163
+ break ;
164
+ case 8 :
165
+ sprite1.normalMapSpriteFrame = torusNormalMap;
166
+ sphereRefraction.normalMap = torusNormalMap;
167
+ sprite1.texture = torusTexture;
168
+
169
+ NSLog (@" Sprite: Torus Effect: Torus - You should see a torus." );
170
+ break ;
171
+ }
172
+ }];
173
+ [sprite2 runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
174
+ [CCActionDelay actionWithDuration: 4 .0f ],
175
+ blockAction,
176
+ nil
177
+ ]]];
178
+
91
179
}
92
180
93
181
-(void )setupBlurEffectNodeTest
0 commit comments