Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am wondering what the best way to approach a "lighting" effect in 2D games is. For instance, if my main character is glowing, what techniques can I use to complete the visual effect of the character glowing when it is near other objects which would be affected by the light?

share|improve this question

4 Answers 4

up vote 35 down vote accepted

You could overlay a simple glow effect texture with soft transparent edges. If you want lighting/shadows similar to what you may find in a 3d world you could do something like this: http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/. However, if you are new to HLSL, then that may be a little bit too much.

edit: I stumbled onto a nice HTML5 2d light tutorial

share|improve this answer
    
That link is exactly what I was looking for. I can't thank you enough; this is extremely helpful. –  Christopher Horenstein Sep 30 '10 at 15:17

After some searching, this blog seemed like a good start:

http://www.soolstyle.com/2010/02/15/2d-deferred-lightning/

be sure to read the comments because there are some improvements there, but the blog post will get you started :).

share|improve this answer

You would need a postfilter shader effect written in HLSL or GLSL. The shader would receive the player coordinates and modify the brightness for all pixels in a certain range. XNA supports 2D shaders quite good.

Another solution would be to simulate brightness by using a texture with an alpha-channel. The texture would be mostly black except for a transparent spot in the middle. This texture we be an overlay over your game screen with the transparent spot centered on the 'glowing' player character. Old adventure games used this technique to simulate flashlights.

share|improve this answer

There is an open-source XNA project which is an excellent library and implementation of 2D lighting that happens to be compatible with XNA 4.0's Reach profile - Krypton XNA.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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