Dark and lighter areas

Hi,

Was wondering how you can have dark sections in a game and light sections. What I mean is, say a lamp on a platform, this would light up certain part of area around it (I’ve done this with checking tiles around it and changing the tint on them) - how would you make it light up anything that comes near it - i.e.sprites such as the player, so for instance player goes right next to light they would light up a lot, move away from light and go they would go darker. Also, enter a dark dungeon with no light, player goes darker.

Would you use a lightmap texture and put this into a framebuffer and use some form of shader on the light map?

I did find this article:

Thanks

[quote=“steveyg90,post:1,topic:57593”]
What happened when you put together a little example program to test that out?

Simplest way: just create an image with a circle that starts out as transparent and fades to fully opaque. Overlay that wherever you have a light, that way stuff further away from the light is darker.

Less simple: Implement a (or better yet, use an existing) light system. Google something like “2d game light system” for a ton of results. I personally like Box2DLights.

Hi,

I didn’t put the demo together, was just a though :wink:

Something like this with the circle image:


batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_SRC_ALPHA);
theLightSprite.draw(batch, parentAlpha);
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

and with Box2DLights:


world = new World(new Vector2(0,0),false);
rayHandler = new RayHandler(world);
rayHandler.setCombinedMatrix(getCamera().combined);
new PointLight(rayHandler,1000, Color.BLUE,20,x,y);      

// in render code
rayHandler.updateAndRender();

Thanks