Skip to content

Commit 3c32259

Browse files
author
Thayer J Andrews
committed
CCEffectsTest - Add varying shininess case to the light parameter test
1 parent 2a166cb commit 3c32259

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ -(void)setupSimpleLightingTest
274274
[light addChild:lightSprite];
275275

276276
CCEffectLighting *lightingEffect = [[CCEffectLighting alloc] initWithLights:@[light]];
277+
lightingEffect.shininess = 10.0f;
277278

278279
CCSprite *sprite = [CCSprite spriteWithImageNamed:diffuseImage];
279280
sprite.positionType = CCPositionTypeNormalized;
@@ -355,15 +356,19 @@ -(void)setupLightingParameterTest
355356
return light;
356357
};
357358

359+
358360
CCLightNode *light = nil;
359-
light = setupBlock(ccp(0.25f, 0.65f), @"Varying Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
361+
CCSprite *sprite = nil;
362+
CCEffectLighting *lighting = nil;
363+
364+
light = setupBlock(ccp(0.2f, 0.65f), @"Varying Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
360365
[CCActionTween actionWithDuration:2 key:@"intensity" from:0.0f to:1.0f],
361366
[CCActionDelay actionWithDuration:2],
362367
[CCActionTween actionWithDuration:2 key:@"intensity" from:1.0f to:0.0f],
363368
nil
364369
]]);
365370
light.ambientIntensity = 0.0f;
366-
light = setupBlock(ccp(0.25f, 0.25f), @"Varying Color", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
371+
light = setupBlock(ccp(0.2f, 0.25f), @"Varying Color", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
367372
[CCActionTintTo actionWithDuration:2 color:[CCColor redColor]],
368373
[CCActionDelay actionWithDuration:1],
369374
[CCActionTintTo actionWithDuration:2 color:[CCColor greenColor]],
@@ -376,13 +381,13 @@ -(void)setupLightingParameterTest
376381
]]);
377382

378383

379-
light = setupBlock(ccp(0.5f, 0.65f), @"Varying Ambient Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
384+
light = setupBlock(ccp(0.4f, 0.65f), @"Varying Ambient Intensity", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
380385
[CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:0.0f to:1.0f],
381386
[CCActionDelay actionWithDuration:2],
382387
[CCActionTween actionWithDuration:2 key:@"ambientIntensity" from:1.0f to:0.0f],
383388
nil
384389
]]);
385-
light = setupBlock(ccp(0.5f, 0.25f), @"Varying Ambient Color", nil);
390+
light = setupBlock(ccp(0.4f, 0.25f), @"Varying Ambient Color", nil);
386391
light.intensity = 0.5f;
387392
light.ambientIntensity = 0.5f;
388393

@@ -392,28 +397,30 @@ -(void)setupLightingParameterTest
392397

393398
typedef void (^AmbientLerpBlock)();
394399
typedef void (^AmbientLerpBuilderBlock)(ccColor4F deltaC);
395-
AmbientLerpBlock (^lerpBuilderBlock)(ccColor4F deltaC) = ^AmbientLerpBlock(ccColor4F deltaC)
400+
401+
__weak CCLightNode *weakLight = light;
402+
AmbientLerpBlock (^ambientLerpBuilder)(ccColor4F deltaC) = ^AmbientLerpBlock(ccColor4F deltaC)
396403
{
397404
AmbientLerpBlock lerpBlock = ^{
398-
ccColor4F c = light.ambientColor.ccColor4f;
405+
ccColor4F c = weakLight.ambientColor.ccColor4f;
399406
c.r += deltaC.r;
400407
c.g += deltaC.g;
401408
c.b += deltaC.b;
402-
light.ambientColor = [CCColor colorWithCcColor4f:c];
409+
weakLight.ambientColor = [CCColor colorWithCcColor4f:c];
403410
};
404411
return lerpBlock;
405412
};
406413

407-
AmbientLerpBlock whiteRedLerp = lerpBuilderBlock(ccc4f(0.0f, -delta, -delta, 0.0f));
414+
AmbientLerpBlock whiteRedLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, -delta, 0.0f));
408415
CCActionInterval *whiteRedLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:whiteRedLerp]] times:120];
409416

410-
AmbientLerpBlock redGreenLerp = lerpBuilderBlock(ccc4f(-delta, delta, 0.0f, 0.0f));
417+
AmbientLerpBlock redGreenLerp = ambientLerpBuilder(ccc4f(-delta, delta, 0.0f, 0.0f));
411418
CCActionInterval *redGreenLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:redGreenLerp]] times:120];
412419

413-
AmbientLerpBlock greenBlueLerp = lerpBuilderBlock(ccc4f(0.0f, -delta, delta, 0.0f));
420+
AmbientLerpBlock greenBlueLerp = ambientLerpBuilder(ccc4f(0.0f, -delta, delta, 0.0f));
414421
CCActionInterval *greenBlueLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:greenBlueLerp]] times:120];
415422

416-
AmbientLerpBlock blueWhiteLerp = lerpBuilderBlock(ccc4f(delta, delta, 0.0f, 0.0f));
423+
AmbientLerpBlock blueWhiteLerp = ambientLerpBuilder(ccc4f(delta, delta, 0.0f, 0.0f));
417424
CCActionInterval *blueWhiteLerpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:blueWhiteLerp]] times:120];
418425

419426
CCAction *ambientLerpAction = [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
@@ -429,16 +436,50 @@ -(void)setupLightingParameterTest
429436
]];
430437
[light runAction:ambientLerpAction];
431438

432-
light = setupBlock(ccp(0.75f, 0.65f), @"Varying Cutoff", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
439+
light = setupBlock(ccp(0.6f, 0.65f), @"Varying Cutoff", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
433440
[CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:1.0f to:500.0f],
434441
[CCActionTween actionWithDuration:2 key:@"cutoffRadius" from:500.0f to:1.0f],
435442
nil
436443
]]);
437-
light = setupBlock(ccp(0.75f, 0.25f), @"Varying Depth", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
444+
light.cutoffRadius = 1.0f;
445+
light = setupBlock(ccp(0.6f, 0.25f), @"Varying Depth", [CCActionRepeatForever actionWithAction:[CCActionSequence actions:
438446
[CCActionTween actionWithDuration:2 key:@"depth" from:1.0f to:500.0f],
439447
[CCActionTween actionWithDuration:2 key:@"depth" from:500.0f to:1.0f],
440448
nil
441449
]]);
450+
light.depth = 1.0f;
451+
sprite = (CCSprite *)light.parent;
452+
lighting = (CCEffectLighting *)sprite.effect;
453+
lighting.shininess = 20.0f;
454+
455+
456+
light = setupBlock(ccp(0.8f, 0.65f), @"Varying Shininess", nil);
457+
sprite = (CCSprite *)light.parent;
458+
lighting = (CCEffectLighting *)sprite.effect;
459+
lighting.shininess = 4.0f;
460+
461+
typedef void (^ShininessLerpBlock)();
462+
typedef void (^ShininessLerpBuilderBlock)(float delta);
463+
ShininessLerpBlock (^shininessLerpBuilder)(float delta) = ^ShininessLerpBlock(float delta)
464+
{
465+
ShininessLerpBlock lerpBlock = ^{
466+
lighting.shininess += delta;
467+
};
468+
return lerpBlock;
469+
};
470+
471+
ShininessLerpBlock shininessRampUp = shininessLerpBuilder(delta * 50.0f);
472+
CCActionInterval *shininessRampUpAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:shininessRampUp]] times:120];
473+
474+
ShininessLerpBlock shininessRampDown = shininessLerpBuilder(-delta * 50.0f);
475+
CCActionInterval *shininessRampDownAction = [CCActionRepeat actionWithAction:[CCActionSequence actionOne:[CCActionDelay actionWithDuration:timeStep] two:[CCActionCallBlock actionWithBlock:shininessRampDown]] times:120];
476+
477+
[light runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions:
478+
shininessRampUpAction,
479+
[CCActionDelay actionWithDuration:1],
480+
shininessRampDownAction,
481+
nil
482+
]]];
442483
}
443484

444485

0 commit comments

Comments
 (0)