Skip to content

Commit 19f1956

Browse files
author
Thayer J Andrews
committed
CCEffectsTest - Add directional light support to the simple lighting test
1 parent 21cb873 commit 19f1956

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -251,46 +251,60 @@ - (void)enableOutline:(id)sender
251251

252252
#endif
253253

254-
-(void)setupLightingEffectTest
254+
-(void)setupSimpleLightingTest
255255
{
256-
self.subTitle = @"Lighting Effect Test";
256+
self.subTitle = @"Simple Lighting Test";
257257

258258
NSString *normalMapImage = @"Images/ShinyTorusNormals.png";
259259
NSString *diffuseImage = @"Images/ShinyTorusColor.png";
260260

261-
CCLightNode *light = [[CCLightNode alloc] init];
262-
light.positionType = CCPositionTypePoints;
263-
light.position = ccp(100.0f, 0.0f);
264-
light.anchorPoint = ccp(0.5f, 0.5f);
265-
light.intensity = 1.0f;
266-
light.ambientIntensity = 0.2f;
267-
light.cutoffRadius = 0.0f;
268-
light.depth = 250.0f;
269-
270-
CCSprite *lightSprite = [CCSprite spriteWithImageNamed:@"Images/snow.png"];
271-
[light addChild:lightSprite];
272-
273-
CCNode *node = [[CCNode alloc] init];
274-
node.positionType = CCPositionTypeNormalized;
275-
node.position = ccp(0.65f, 0.5f);
276-
node.anchorPoint = ccp(0.5f, 0.5f);
277-
278-
[node addChild:light];
261+
void (^setupBlock)(CGPoint position, CCLightType type, float lightDepth, NSString *title) = ^void(CGPoint position, CCLightType type, float lightDepth, NSString *title)
262+
{
263+
CCLightNode *light = [[CCLightNode alloc] init];
264+
light.type = type;
265+
light.positionType = CCPositionTypeNormalized;
266+
light.position = ccp(0.5f, 0.5f);
267+
light.anchorPoint = ccp(0.5f, 0.5f);
268+
light.intensity = 1.0f;
269+
light.ambientIntensity = 0.2f;
270+
light.cutoffRadius = 0.0f;
271+
light.depth = lightDepth;
272+
273+
CCSprite *lightSprite = [CCSprite spriteWithImageNamed:@"Images/snow.png"];
274+
[light addChild:lightSprite];
275+
276+
CCEffectLighting *lightingEffect = [[CCEffectLighting alloc] initWithLights:@[light]];
277+
278+
CCSprite *sprite = [CCSprite spriteWithImageNamed:diffuseImage];
279+
sprite.positionType = CCPositionTypeNormalized;
280+
sprite.position = position;
281+
sprite.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed:normalMapImage];
282+
sprite.effect = lightingEffect;
283+
sprite.scale = 0.5f;
284+
285+
[self.contentNode addChild:sprite];
286+
287+
[sprite addChild:light];
288+
289+
CCLabelTTF *label = [CCLabelTTF labelWithString:title fontName:@"HelveticaNeue-Light" fontSize:18 * [CCDirector sharedDirector].UIScaleFactor];
290+
label.color = [CCColor whiteColor];
291+
label.positionType = CCPositionTypeNormalized;
292+
label.position = ccp(0.5f, 1.1f);
293+
label.horizontalAlignment = CCTextAlignmentCenter;
294+
295+
[sprite addChild:label];
279296

280-
CCEffectLighting *lightingEffect = [[CCEffectLighting alloc] initWithLights:@[light]];
281-
282-
CCSprite *sprite = [CCSprite spriteWithImageNamed:diffuseImage];
283-
sprite.positionType = CCPositionTypeNormalized;
284-
sprite.position = ccp(0.5f, 0.5f);
285-
sprite.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed:normalMapImage];
286-
sprite.effect = lightingEffect;
287-
sprite.scale = 0.5f;
288-
289-
[self.contentNode addChild:sprite];
290-
[self.contentNode addChild:node];
291-
292-
[node runAction:[CCActionRepeatForever actionWithAction:[CCActionRotateBy actionWithDuration:1.0 angle:45.0]]];
293-
[light runAction:[CCActionRepeatForever actionWithAction:[CCActionRotateBy actionWithDuration:1.0 angle:-45.0]]];
297+
298+
[light runAction:[CCActionRepeatForever actionWithAction:[CCActionSequence actions:
299+
[CCActionMoveTo actionWithDuration:1.0 position:ccp(1.0f, 1.0f)],
300+
[CCActionMoveTo actionWithDuration:2.0 position:ccp(0.0f, 0.0f)],
301+
[CCActionRotateBy actionWithDuration:5.0 angle:360.0],
302+
[CCActionMoveTo actionWithDuration:1.0 position:ccp(0.5f, 0.5f)],
303+
nil
304+
]]];
305+
};
306+
setupBlock(ccp(0.25f, 0.5f), CCLightPoint, 250.0f, @"Point Light\nPosition matters, orientation does not.");
307+
setupBlock(ccp(0.75f, 0.5f), CCLightDirectional, 1.0f, @"Directional Light\nPosition does not matter, orientation does.");
294308
}
295309

296310
-(void)setupPaddingEffectTest

0 commit comments

Comments
 (0)