@@ -274,6 +274,7 @@ -(void)setupSimpleLightingTest
274
274
[light addChild: lightSprite];
275
275
276
276
CCEffectLighting *lightingEffect = [[CCEffectLighting alloc ] initWithLights: @[light]];
277
+ lightingEffect.shininess = 10 .0f ;
277
278
278
279
CCSprite *sprite = [CCSprite spriteWithImageNamed: diffuseImage];
279
280
sprite.positionType = CCPositionTypeNormalized;
@@ -355,15 +356,19 @@ -(void)setupLightingParameterTest
355
356
return light;
356
357
};
357
358
359
+
358
360
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:
360
365
[CCActionTween actionWithDuration: 2 key: @" intensity" from: 0 .0f to: 1 .0f ],
361
366
[CCActionDelay actionWithDuration: 2 ],
362
367
[CCActionTween actionWithDuration: 2 key: @" intensity" from: 1 .0f to: 0 .0f ],
363
368
nil
364
369
]]);
365
370
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:
367
372
[CCActionTintTo actionWithDuration: 2 color: [CCColor redColor ]],
368
373
[CCActionDelay actionWithDuration: 1 ],
369
374
[CCActionTintTo actionWithDuration: 2 color: [CCColor greenColor ]],
@@ -376,13 +381,13 @@ -(void)setupLightingParameterTest
376
381
]]);
377
382
378
383
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:
380
385
[CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 0 .0f to: 1 .0f ],
381
386
[CCActionDelay actionWithDuration: 2 ],
382
387
[CCActionTween actionWithDuration: 2 key: @" ambientIntensity" from: 1 .0f to: 0 .0f ],
383
388
nil
384
389
]]);
385
- light = setupBlock (ccp (0 .5f , 0 .25f ), @" Varying Ambient Color" , nil );
390
+ light = setupBlock (ccp (0 .4f , 0 .25f ), @" Varying Ambient Color" , nil );
386
391
light.intensity = 0 .5f ;
387
392
light.ambientIntensity = 0 .5f ;
388
393
@@ -392,28 +397,30 @@ -(void)setupLightingParameterTest
392
397
393
398
typedef void (^AmbientLerpBlock)();
394
399
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)
396
403
{
397
404
AmbientLerpBlock lerpBlock = ^{
398
- ccColor4F c = light .ambientColor .ccColor4f ;
405
+ ccColor4F c = weakLight .ambientColor .ccColor4f ;
399
406
c.r += deltaC.r ;
400
407
c.g += deltaC.g ;
401
408
c.b += deltaC.b ;
402
- light .ambientColor = [CCColor colorWithCcColor4f: c];
409
+ weakLight .ambientColor = [CCColor colorWithCcColor4f: c];
403
410
};
404
411
return lerpBlock;
405
412
};
406
413
407
- AmbientLerpBlock whiteRedLerp = lerpBuilderBlock (ccc4f (0 .0f , -delta, -delta, 0 .0f ));
414
+ AmbientLerpBlock whiteRedLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, -delta, 0 .0f ));
408
415
CCActionInterval *whiteRedLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: whiteRedLerp]] times: 120 ];
409
416
410
- AmbientLerpBlock redGreenLerp = lerpBuilderBlock (ccc4f (-delta, delta, 0 .0f , 0 .0f ));
417
+ AmbientLerpBlock redGreenLerp = ambientLerpBuilder (ccc4f (-delta, delta, 0 .0f , 0 .0f ));
411
418
CCActionInterval *redGreenLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: redGreenLerp]] times: 120 ];
412
419
413
- AmbientLerpBlock greenBlueLerp = lerpBuilderBlock (ccc4f (0 .0f , -delta, delta, 0 .0f ));
420
+ AmbientLerpBlock greenBlueLerp = ambientLerpBuilder (ccc4f (0 .0f , -delta, delta, 0 .0f ));
414
421
CCActionInterval *greenBlueLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: greenBlueLerp]] times: 120 ];
415
422
416
- AmbientLerpBlock blueWhiteLerp = lerpBuilderBlock (ccc4f (delta, delta, 0 .0f , 0 .0f ));
423
+ AmbientLerpBlock blueWhiteLerp = ambientLerpBuilder (ccc4f (delta, delta, 0 .0f , 0 .0f ));
417
424
CCActionInterval *blueWhiteLerpAction = [CCActionRepeat actionWithAction: [CCActionSequence actionOne: [CCActionDelay actionWithDuration: timeStep] two: [CCActionCallBlock actionWithBlock: blueWhiteLerp]] times: 120 ];
418
425
419
426
CCAction *ambientLerpAction = [CCActionRepeatForever actionWithAction: [CCActionSequence actions:
@@ -429,16 +436,50 @@ -(void)setupLightingParameterTest
429
436
]];
430
437
[light runAction: ambientLerpAction];
431
438
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:
433
440
[CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 1 .0f to: 500 .0f ],
434
441
[CCActionTween actionWithDuration: 2 key: @" cutoffRadius" from: 500 .0f to: 1 .0f ],
435
442
nil
436
443
]]);
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:
438
446
[CCActionTween actionWithDuration: 2 key: @" depth" from: 1 .0f to: 500 .0f ],
439
447
[CCActionTween actionWithDuration: 2 key: @" depth" from: 500 .0f to: 1 .0f ],
440
448
nil
441
449
]]);
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
+ ]]];
442
483
}
443
484
444
485
0 commit comments