@@ -12,6 +12,7 @@ @implementation CCEffectsTest {
12
12
#if CC_EFFECTS_EXPERIMENTAL
13
13
CCEffectDistanceField* _distanceFieldEffect;
14
14
CCEffectDFOutline* _outlineEffect;
15
+ CCEffectDFInnerGlow* _innerGlowEffect;
15
16
#endif
16
17
}
17
18
@@ -29,6 +30,56 @@ -(id)init
29
30
30
31
#if CC_EFFECTS_EXPERIMENTAL
31
32
33
+ -(void )setupDFInnerGlowTest
34
+ {
35
+ self.subTitle = @" Distance Field Inner Glow Test" ;
36
+
37
+ CCSprite *environment = [CCSprite spriteWithImageNamed: @" Images/MountainPanorama.jpg" ];
38
+ environment.positionType = CCPositionTypeNormalized;
39
+ environment.anchorPoint = ccp (0.5 , 0.5 );
40
+ environment.position = ccp (0 .5f , 0 .5f );
41
+
42
+ CCTexture* texture = [[CCTextureCache sharedTextureCache ] addImage: @" Images/output.png" ];
43
+
44
+ CCColor* fillColor = [CCColor colorWithRed: 0.0 green: 1.0 blue: 0.0 alpha: 0.5 ];
45
+ _innerGlowEffect = [CCEffectDFInnerGlow effectWithGlowColor: [CCColor redColor ] fillColor: fillColor glowWidth: 2 fieldScale: 32 distanceField: texture];
46
+
47
+ CCSprite *dfSprite = [CCSprite spriteWithImageNamed: @" Images/df_sprite.png" ];
48
+ dfSprite.position = ccp (0.5 , 0.5 );
49
+ dfSprite.positionType = CCPositionTypeNormalized;
50
+ dfSprite.effect = _innerGlowEffect;
51
+ dfSprite.scale = 1 .0f ;
52
+
53
+ CCSpriteFrame* background = [CCSpriteFrame frameWithImageNamed: @" Tests/slider-background.png" ];
54
+ CCSpriteFrame* backgroundHilite = [CCSpriteFrame frameWithImageNamed: @" Tests/slider-background-hilite.png" ];
55
+ CCSpriteFrame* handle = [CCSpriteFrame frameWithImageNamed: @" Tests/slider-handle.png" ];
56
+
57
+ CCSlider* slider = [[CCSlider alloc ] initWithBackground: background andHandleImage: handle];
58
+ [slider setBackgroundSpriteFrame: backgroundHilite forState: CCControlStateHighlighted];
59
+ slider.positionType = CCPositionTypeNormalized;
60
+ slider.position = ccp (0 .1f , 0 .5f );
61
+ slider.sliderValue = 0.3 ;
62
+ slider.preferredSizeType = CCSizeTypeMake (CCSizeUnitNormalized, CCSizeUnitUIPoints);
63
+ slider.preferredSize = CGSizeMake (0 .5f , 10 );
64
+ slider.rotation = 90 ;
65
+ slider.anchorPoint = ccp (0 .5f , 0 .5f );
66
+ slider.scale = 0.8 ;
67
+
68
+ [slider setTarget: self selector: @selector (innerGlowWidthChanged: )];
69
+
70
+ [self .contentNode addChild: environment];
71
+ [self .contentNode addChild: slider];
72
+ [self .contentNode addChild: dfSprite];
73
+ }
74
+
75
+ - (void )innerGlowWidthChanged : (id )sender
76
+ {
77
+ const int innerGloWMax = 6 ;
78
+ CCSlider* slider = sender;
79
+ _innerGlowEffect.glowWidth = slider.sliderValue * innerGloWMax;
80
+ }
81
+
82
+
32
83
-(void )setupDFOutlineEffectTest
33
84
{
34
85
self.subTitle = @" Distance Field Outline Test" ;
@@ -40,8 +91,8 @@ -(void)setupDFOutlineEffectTest
40
91
41
92
CCTexture* texture = [[CCTextureCache sharedTextureCache ] addImage: @" Images/output.png" ];
42
93
43
- CCColor* fillColor = [CCColor colorWithRed: 0.0 green: 0.0 blue: 0 .0 alpha: 0.0 ];
44
- _outlineEffect = [CCEffectDFOutline effectWithOutlineColor: [CCColor redColor ] fillColor: fillColor outlineWidth: 3 fieldScale: 32 distanceField: texture];
94
+ CCColor* fillColor = [CCColor colorWithRed: 0.0 green: 0.0 blue: 1 .0 alpha: 0.0 ];
95
+ _outlineEffect = [CCEffectDFOutline effectWithOutlineColor: [CCColor redColor ] fillColor: fillColor outlineWidth: 1 fieldScale: 32 distanceField: texture];
45
96
46
97
CCSprite *dfSprite = [CCSprite spriteWithImageNamed: @" Images/df_sprite.png" ];
47
98
dfSprite.position = ccp (0.5 , 0.5 );
@@ -57,12 +108,12 @@ -(void)setupDFOutlineEffectTest
57
108
[slider setBackgroundSpriteFrame: backgroundHilite forState: CCControlStateHighlighted];
58
109
slider.positionType = CCPositionTypeNormalized;
59
110
slider.position = ccp (0 .1f , 0 .5f );
60
-
61
111
slider.preferredSizeType = CCSizeTypeMake (CCSizeUnitNormalized, CCSizeUnitUIPoints);
62
112
slider.preferredSize = CGSizeMake (0 .5f , 10 );
63
113
slider.rotation = 90 ;
64
114
slider.anchorPoint = ccp (0 .5f , 0 .5f );
65
115
slider.scale = 0.8 ;
116
+ slider.sliderValue = 0.1 ;
66
117
67
118
[slider setTarget: self selector: @selector (outlineWidthChagne: )];
68
119
@@ -200,6 +251,151 @@ - (void)enableOutline:(id)sender
200
251
201
252
#endif
202
253
254
+ -(void )setupPaddingEffectTest
255
+ {
256
+ self.subTitle = @" Effect Padding Test" ;
257
+
258
+ {
259
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
260
+ sprite.positionType = CCPositionTypeNormalized;
261
+ sprite.position = ccp (0 .75f , 0 .8f );
262
+
263
+ [self .contentNode addChild: sprite];
264
+
265
+ CCLabelTTF *title = [CCLabelTTF labelWithString: @" Original Sprite" fontName: @" HelveticaNeue-Light" fontSize: 14 * [CCDirector sharedDirector ].UIScaleFactor];
266
+ title.color = [CCColor whiteColor ];
267
+ title.positionType = CCPositionTypeNormalized;
268
+ title.position = ccp (0 .25f , 0 .8f );
269
+ title.horizontalAlignment = CCTextAlignmentCenter;
270
+
271
+ [self .contentNode addChild: title];
272
+ }
273
+
274
+ {
275
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
276
+ sprite.positionType = CCPositionTypeNormalized;
277
+ sprite.position = ccp (0 .75f , 0 .65f );
278
+
279
+ CCEffectColorChannelOffset *offset = [CCEffectColorChannelOffset effectWithRedOffset: GLKVector2Make (5 .0f , 0 .0f ) greenOffset: GLKVector2Make (-4 .0f , 4 .0f ) blueOffset: GLKVector2Make (-4 .0f , -4 .0f )];
280
+ sprite.effect = offset;
281
+
282
+ [self .contentNode addChild: sprite];
283
+
284
+ CCLabelTTF *title = [CCLabelTTF labelWithString: @" Color channel offset without padding" fontName: @" HelveticaNeue-Light" fontSize: 14 * [CCDirector sharedDirector ].UIScaleFactor];
285
+ title.color = [CCColor whiteColor ];
286
+ title.positionType = CCPositionTypeNormalized;
287
+ title.position = ccp (0 .25f , 0 .65f );
288
+ title.horizontalAlignment = CCTextAlignmentCenter;
289
+
290
+ [self .contentNode addChild: title];
291
+ }
292
+
293
+ {
294
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
295
+ sprite.positionType = CCPositionTypeNormalized;
296
+ sprite.position = ccp (0 .75f , 0 .5f );
297
+
298
+ CCEffectColorChannelOffset *offset = [CCEffectColorChannelOffset effectWithRedOffset: GLKVector2Make (5 .0f , 0 .0f ) greenOffset: GLKVector2Make (-4 .0f , 4 .0f ) blueOffset: GLKVector2Make (-4 .0f , -4 .0f )];
299
+ offset.padding = CGSizeMake (5 .0f , 5 .0f );
300
+ sprite.effect = offset;
301
+
302
+ [self .contentNode addChild: sprite];
303
+
304
+ CCLabelTTF *title = [CCLabelTTF labelWithString: @" Color channel offset with padding" fontName: @" HelveticaNeue-Light" fontSize: 14 * [CCDirector sharedDirector ].UIScaleFactor];
305
+ title.color = [CCColor whiteColor ];
306
+ title.positionType = CCPositionTypeNormalized;
307
+ title.position = ccp (0 .25f , 0 .5f );
308
+ title.horizontalAlignment = CCTextAlignmentCenter;
309
+
310
+ [self .contentNode addChild: title];
311
+ }
312
+
313
+ {
314
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
315
+ sprite.positionType = CCPositionTypeNormalized;
316
+ sprite.position = ccp (0 .75f , 0 .35f );
317
+
318
+ CCEffectColorChannelOffset *offset = [CCEffectColorChannelOffset effectWithRedOffset: GLKVector2Make (5 .0f , 0 .0f ) greenOffset: GLKVector2Make (-4 .0f , 4 .0f ) blueOffset: GLKVector2Make (-4 .0f , -4 .0f )];
319
+ offset.padding = CGSizeMake (5 .0f , 5 .0f );
320
+ CCEffectHue *hue = [CCEffectHue effectWithHue: 60 .0f ];
321
+ sprite.effect = [CCEffectStack effectWithArray: @[offset, hue]];
322
+
323
+ [self .contentNode addChild: sprite];
324
+
325
+ CCLabelTTF *title = [CCLabelTTF labelWithString: @" Padded effect stack (offset then hue)" fontName: @" HelveticaNeue-Light" fontSize: 14 * [CCDirector sharedDirector ].UIScaleFactor];
326
+ title.color = [CCColor whiteColor ];
327
+ title.positionType = CCPositionTypeNormalized;
328
+ title.position = ccp (0 .25f , 0 .35f );
329
+ title.horizontalAlignment = CCTextAlignmentCenter;
330
+
331
+ [self .contentNode addChild: title];
332
+ }
333
+
334
+ {
335
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
336
+ sprite.positionType = CCPositionTypeNormalized;
337
+ sprite.position = ccp (0 .75f , 0 .2f );
338
+
339
+ CCEffectColorChannelOffset *offset = [CCEffectColorChannelOffset effectWithRedOffset: GLKVector2Make (5 .0f , 0 .0f ) greenOffset: GLKVector2Make (-4 .0f , 4 .0f ) blueOffset: GLKVector2Make (-4 .0f , -4 .0f )];
340
+ offset.padding = CGSizeMake (5 .0f , 5 .0f );
341
+ CCEffectHue *hue = [CCEffectHue effectWithHue: 60 .0f ];
342
+ sprite.effect = [CCEffectStack effectWithArray: @[hue, offset]];
343
+
344
+ [self .contentNode addChild: sprite];
345
+
346
+ CCLabelTTF *title = [CCLabelTTF labelWithString: @" Padded efect stack (hue then offset)" fontName: @" HelveticaNeue-Light" fontSize: 14 * [CCDirector sharedDirector ].UIScaleFactor];
347
+ title.color = [CCColor whiteColor ];
348
+ title.positionType = CCPositionTypeNormalized;
349
+ title.position = ccp (0 .25f , 0 .2f );
350
+ title.horizontalAlignment = CCTextAlignmentCenter;
351
+
352
+ [self .contentNode addChild: title];
353
+ }
354
+ }
355
+
356
+ -(void )setupColorChannelOffsetTest
357
+ {
358
+ self.subTitle = @" Color Channel Offset Effect Test" ;
359
+
360
+ CCEffectColorChannelOffset *effect = [CCEffectColorChannelOffset effectWithRedOffset: GLKVector2Make (0 .0f , 0 .0f ) greenOffset: GLKVector2Make (0 .0f , 0 .0f ) blueOffset: GLKVector2Make (0 .0f , 0 .0f )];
361
+ effect.padding = CGSizeMake (5 .0f , 5 .0f );
362
+
363
+ CCSprite *sprite = [CCSprite spriteWithImageNamed: @" Images/particles.png" ];
364
+ sprite.scale = 1 .0f ;
365
+ sprite.positionType = CCPositionTypeNormalized;
366
+ sprite.position = ccp (0 .5f , 0 .5f );
367
+ sprite.effect = effect;
368
+
369
+ [self .contentNode addChild: sprite];
370
+
371
+ const float thetaStep = CC_DEGREES_TO_RADIANS (10 .0f );
372
+ __block float redTheta = CC_DEGREES_TO_RADIANS (0 .0f );
373
+ __block float greenTheta = CC_DEGREES_TO_RADIANS (120 .0f );
374
+ __block float blueTheta = CC_DEGREES_TO_RADIANS (240 .0f );
375
+ void (^updateBlock)() = ^{
376
+
377
+ float redRadius = 3 .0f ;
378
+ effect.redOffset = GLKVector2Make (redRadius * cosf (redTheta), redRadius * sinf (redTheta));
379
+
380
+ float greenRadius = 3 .0f ;
381
+ effect.greenOffset = GLKVector2Make (greenRadius * cosf (greenTheta), greenRadius * sinf (greenTheta));
382
+
383
+ float blueRadius = 3 .0f ;
384
+ effect.blueOffset = GLKVector2Make (blueRadius * cosf (blueTheta), blueRadius * sinf (blueTheta));
385
+
386
+ redTheta += thetaStep;
387
+ greenTheta += thetaStep;
388
+ blueTheta += thetaStep;
389
+ };
390
+ updateBlock ();
391
+
392
+ [sprite runAction: [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
393
+ [CCActionDelay actionWithDuration: 0 .1f ],
394
+ [CCActionCallBlock actionWithBlock: updateBlock],
395
+ nil
396
+ ]]];
397
+ }
398
+
203
399
#pragma mark DropShadow
204
400
205
401
-(void )setupDropShadowEffectTest
@@ -608,13 +804,14 @@ -(void)setupBloomEffectTest
608
804
const int steps = 5 ;
609
805
for (int i = 0 ; i < steps; i++)
610
806
{
611
- CCSprite *sampleSprite3 = [CCSprite spriteWithImageNamed: @" Images/grossini_dance_08 .png" ];
807
+ CCSprite *sampleSprite3 = [CCSprite spriteWithImageNamed: @" Images/f1 .png" ];
612
808
sampleSprite3.anchorPoint = ccp (0.5 , 0.5 );
613
809
sampleSprite3.position = ccp (0 .1f + i * (0 .8f / (steps - 1 )), 0 .2f );
614
810
sampleSprite3.positionType = CCPositionTypeNormalized;
615
811
616
812
// Blend glow maps test
617
- CCEffectBloom* glowEffect3 = [CCEffectBloom effectWithBlurRadius: 3 intensity: 1 .0f luminanceThreshold: 1 .0f - ((float )i/(float )(steps-1 ))];
813
+ CCEffectBloom* glowEffect3 = [CCEffectBloom effectWithBlurRadius: 8 intensity: 1 .0f luminanceThreshold: 1 .0f - ((float )i/(float )(steps-1 ))];
814
+ glowEffect3.padding = CGSizeMake (10 .0f , 10 .0f );
618
815
sampleSprite3.effect = glowEffect3;
619
816
620
817
[self .contentNode addChild: sampleSprite3];
0 commit comments