1
votes

I have a 2D tile map in java (using libgdx no Tiled Map Editor) formed with squares and I want the tiles to gradually become darker until they won't be visible. So basically I don't want round light. The only option I know is to use alpha channel and make every tile from the source which is the player become less visible. I want to know how can I implement this using a shader. I want to render my map normally with a spritebacth and then apply the shader to my spritebacth, so I can render the light effect. Each tile should have it's own visibility. An example of a game which uses the kind of lightning I want is: http://www.desura.com/games/fragile-soul

1

1 Answers

0
votes

Render each tile itself via SpriteBatch and use spriteBatch.setColor(r, g, b, a) with different "grey" values.

The tile where your player is standing on will start with white, so spriteBatch.setColor(1, 1, 1, 1) before rendering that one. And then linearly decrease the brightness for the other ones in a radius around.

For example all tiles one next to the player might get spriteBatch.setColor(0.8f, 0.8f, 0.8f, 1f) resulting in a slightly darker tile. You do this until you reach black via spriteBatch.setColor(0, 0, 0, 1). All those tiles will be completely black.