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?
4 Answers
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
-
\$\begingroup\$ That link is exactly what I was looking for. I can't thank you enough; this is extremely helpful. \$\endgroup\$ Commented Sep 30, 2010 at 15:17
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.
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.
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 :).