@@ -251,46 +251,60 @@ - (void)enableOutline:(id)sender
251
251
252
252
#endif
253
253
254
- -(void )setupLightingEffectTest
254
+ -(void )setupSimpleLightingTest
255
255
{
256
- self.subTitle = @" Lighting Effect Test" ;
256
+ self.subTitle = @" Simple Lighting Test" ;
257
257
258
258
NSString *normalMapImage = @" Images/ShinyTorusNormals.png" ;
259
259
NSString *diffuseImage = @" Images/ShinyTorusColor.png" ;
260
260
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];
279
296
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\n Position matters, orientation does not." );
307
+ setupBlock (ccp (0 .75f , 0 .5f ), CCLightDirectional, 1 .0f , @" Directional Light\n Position does not matter, orientation does." );
294
308
}
295
309
296
310
-(void )setupPaddingEffectTest
0 commit comments