Tutorial by Andreas Loew / CodeAndWeb GmbH Thanks for collidernyc from Cocos2d Forum for the Swift port
This demo uses the same normal mapped sprite in different dynamic light scenarios. The light source can be dragged do light the sprite from different angles.
Read the full tutorial: Cocos2d Dynamic Lighting Tutorial
- Bright yellow directional light
- Bright ambient light
- Bright light blue directional light
- Bright light blue ambient light
- Snow particles (no light effect, just for the fun)
- White point light (restricted radius)
- Dark gray ambient light
- Orange point light (restricted radius)
- Dark blue ambient light
- Fire particles (no light effect, just for the fun)
- Animated ligth source position (flickering)
All light effects are calculated in real time using Cocos2D's lighting system.
A normal mapped sprite consists of 2 files:
The texture itself is used for the sprite's color.
The pixels in the normal map represent a direction - the direction in which the normal vector of a given pixel is pointing. It's encoded into the color channe - this is where the strange color scheme comes from.
The normal maps were generated using SpriteIlluminator - our Normal Map Generator.
Read the full tutorial: Cocos2d Dynamic Lighting Tutorial