0
\$\begingroup\$

I wanted to add some lighting effects to my game. The only way I know t achieve this is through a shader who calculates the lighting. But for multiple lightsources it's a bit complex at the moment. Is there an easier way to just create an overlay lighting effect?

\$\endgroup\$
0
\$\begingroup\$

You can simply darken the entire scene and add a kind of sprite lighting to the parts you want illuminated. For example this was used in the SNES Zelda and other games back in the day.

They would make the whole scene almost totally black in the caves for example and when you light a candle you get a bubble of light around you. Also torches on the wall would have the same sprite surrounding them.

Its not the best looking effect in the world but its sure easy and does add a nice little touch to 2d games.

light sprite

Of course remember to add alpha channel for transparency of the light and this works best when the scene is very dark.

Im sure there are better solutions but this is one ive used in the past just to add a little touch to my games without using shaders / particle systems and other lighting effects

|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

The answer to this related question on SO gives a simple solution to the problem. Use a texture like this (this one s CC0, use as you wish):

light patch

Then when you draw this sprite you blend it with the background:

batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_SRC_ALPHA); // Blend with background
theLightSprite.draw(batch, parentAlpha); // Draw the circle of light
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); // Normal rendering
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ ok, so tried it and it worked somehow. But zou can still see where the texture begins/ends. \$\endgroup\$ – mrdlink Jul 26 '17 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.