Libgdx 2D lights

I’m attempting to figure out how I can add lights to my current game, it’s top down 2d and there need to be multiple instances of the lights that are moving. I’ll focus on making them dynamic at another date. But, I have no idea how i would do this with libgdx. Any further details can be provided at request. Any help or suggestions is greatly appreciated.

Box2dLights, for instance.

Also notice that only need box2d for shadows. So adding light library work fine even without box2d.

Well, I guess I’m not so much looking for lighting as I am for creating an alpha mask. That seems like a more reasonable approach to what I’m doing.

Whoa, this looks awesome, thanks! ;D

And each flying bullet gets it own moving light as well :slight_smile:
Kudos to Pitbuller for this little library which allows to enlighten your game without having the slightest clue about the low level details inside.

I think you need to be more specific about your requirements. You have the alpha channel in color objects for instance.

If you just want black where there are no light and completely white neutral light that does not distort you game colors that library can do that too. But you need be more specific what you want.

Slightly off-topic, but still about lighting and visibility, this is a great read with some nice interactive apps embedded on the page:

2d Visibility from Red Blob Games

;D

As I said that I was really only looking for a method to make an alpha mask, I’ve finally found something suitable. However, it seems as though it is not efficient at all. This is what I’ve got.


      Pixmap lightMesh = new Pixmap(width, height, Pixmap.Format.RGBA8888);
      Blending blending = Pixmap.getBlending();
		lightMesh.setColor(0f, 0f, 0f, 0f);
		Pixmap.setBlending(Blending.None);

		int newX = Math.round(x);
		int newY = Math.round(y);

		lightMesh.fillCircle(newX, newY, radius);
		Pixmap.setBlending(blending);
		lightMesh.setColor(Color.BLACK);

Pixmaps are performed on CPU. Before rendering something to the screen, you need to upload the Pixmap RGBA data to the GPU onto a Texture. This is explained here:

Maybe you could explain your situation in more detail, with screenshots of what you’re trying to do. If you just want masks, see here:

If you just want feathered circles for point lights, you could use a simple PNG sprite or shaders:

Ultimately box2dlights is really the best choice for 2D lights. It uses a disc geometry to reduce fill rate which means that multiple lights will perform better on Android. And it should be easy to make it dynamic later on in your game, via box2d.