Pergunta

Is it possible to simulate a candle for instance in cocos2d. So the scene will be black and then when the candle appears it will lighten up the room in a realistic way.

If possible, how would I achieve that effect? Any redirections, guidance is welcome.

Thanks.

Please note, that I don't want light reflection algorithms, as this is only for simple use. I just need it for a game where the players life is the abillity to see the room.

Foi útil?

Solução

You should check out raycasting. If you set up Cocos2d to use Box2d, you can use Box2d's raycasting method to achieve this effect. You can make the walls in your room box2d rigid-bodies, and then raycast from your candle origin to a number of points on a circle around it. If the raycast intersects a wall, mark the location of the intersection. Then at the end you can fill in the area with light that is inside a polygon created by all of the raycast intersection points.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top