Springrbua Springrbua - 1 year ago 212
Java Question

Libgdx light without box2d

I just started creating a game using libgdx. It is a top down 2d shooter using scene2d ui. Now i thought, that i could add darkness and light to some levels, but i don't want to rewrite everything using box2d. I don't need realistic shadows just some kind of ambient light and a lightcircle arround my character, which is not affected by walls and other obstacles arround him. So i wanted to know if there is any kind of lightsystem in libgdx? Or can i use box2dlights without using box2d bodies/world...? Thanks

Answer Source

Unfortunately there is nothing like this already provided by LibGDX.

But you can easily do it yourself if you do not want shadows.

Here is a little video of someone who has done it via LibGDX. Here is the article to this video, with code and descriptions and everything provided. You can do it this way with shaders, but you could also do the same by just rendering a lightmap to an FBO (in the given links you can see how to do that) and then just render it the usual way with blending activated on top of your screen. The standard SpriteBatch can do that and you don't need any custom shaders.

If you still want to have real shadows with obstacles, you will probably find this article very useful. But this is a lot slower and needs special shaders.

There is also no way to use Box2dLights without Box2D btw.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download