Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Wow, I'm super exited about this, got a few lights working into the game, this is only a simple effect. Meaning, no shadows or anything like that. The most surprising thing to me was that I could get it working without shaders(other than the default one, of course).

Here is how it works(thanks to Kedu at http://stackoverflow.com/questions/21278229/libgdx..., who actually figured out the solution), you get a sprite for your light. Then you draw a black translucent quad covering the whole scene. You should get a darkened version of your scene. How I did it:

game.batch.setColor(0, 0, 0, 0.7f);
game.batch.draw(black, 0, 0, 800, 600); // Draws a black texture over the whole screen
game.batch.setColor(1, 1, 1, 1);

So far so good, after you darkened your scene, it's a matter of using your sprite to light the appropriate parts of it. How? The blendFunctions from OpenGL. Before you draw your lights, you should do:

game.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_SRC_ALPHA);

The first parameter means you'll be multiplying the source color by the destination color. As the source color is white, the resulting color will be the destination color, a little darkened around the center(see the light texture). And the second argument means the destination color will be multiplied by the alpha of the src color(that is, 1) so it will get a little brighter.

You draw your texture wherever you want, and reset the blendFunc to the default one:

game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

This will only get the blending back to normal. Screen shots:

Note: You can change the color of the light by just changing the color of the spritebatch before drawing it.

I have just learned all of this, so I may have missed or misunderstood something, if so, please correct me. I think this method is quite good as it doesn't require coding a shader that will implement basic functionality that opengl has anyways. Have a nice one!