Lighting and shadows with Cocos2D and Box2D

Simen Øian Gjermundsen picture Simen Øian Gjermundsen · Nov 7, 2011 · Viewed 7.7k times · Source

I am currently developing a game for iPad & iPhone using Cocos2d with Box2d. It would have been majorly cool to achieve a lighting effect like the one in this video:

http://www.youtube.com/watch?v=Elnpm-gNI04

and on this link:

http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/

I could have a go at trying to replicate the effect with Cocos2d and Box2d from the description in the link, but I am unsure if I would be able to get very far. It looks pretty advanced and heavy.

How can I achieve this in an "easy" way? Does anyone know of a Cocos2d-version of something like this, or do anyone have some pointers to point me in the right direction?

Answer

kalle hämäläinen picture kalle hämäläinen · Jan 28, 2012

http://code.google.com/p/box2dlights/ I have succesfully made dynamic light library that use box2d geometry and rayCasting. My library work under gles1.0 and gles2.0 and use libgdx as framework. This is peformant enough for giving dynamic real time lights to 2d games for mobile devices. I can help with porting that to Cocos2D. Basics are darn simple. It was under 100 lines when I first hacked it working for my own game.

Example: Point light shoot from center n number of rays around it and record the closest collision points. These collision points are used for mesh that is colored with gradient and drawed with additive blending.