What do 3d games have that we clickers don't? Support for vertex lighting is one! A good lighting system adds a huge amount of atmosphere to a game, expecially horror oriented ones.

In this article I will explain how to add a lighting system to your game that, whilst not being vertex lighting, can interact with light sources and create some pretty cool effects!


1. First of all check what type of game you are making this for. If it is a non-scroller, I probably wouldn't bother. I found this system to work best on platform games or top down shooters. Also check your screen size. This system is not recomended for screen resolutions above 640x480 as it would run very slowly.

2. Go into paint, and make a 1x1 pixel bitmap. colour it black for now.

3. Create an active picture object in your game- make this the same size as your window size. Set it to not follow the playfield (follow the screen). Name it "light".

4. Now you need to sort out some values for this object. Although you can't name active picture alt values, I will give them names so that you know what i am talking about.
The values will be:

Ambient light
Dynamic light

5. Leave that for now. Now you need to make the light sources. Create an active object and re-name it "light source". Light sources need values aswell, and this time you can name them:

Light intensity
Distance from window centre
Amount of illumination
ID number

6. Now you can start putting some code in:

Start of frame

- Spread value 1 in ID number("light source")


- set distance from window centre("light source") to distancebp(x left frame+(frame width/2), y top frame+(frame height/2), X("light source"), Y("light source))
- set amount of illimunation("light source") to light intensity("light source")/Distance from window centre("light source")
-Set Dynamic light("light") to 0
-Start loop "lighting" for (object count("light source")) loops

On loop "lighting"
+ ID number("light source")= loopindex "lighting"

- Set Dynamic light("light") to Dynamic light("light")+Amount of illumination("light source")


- Set semi-transparency ratio("light") to Dynamic light("light")+Ambient light("light")

7. Now place some light sources about randomly, and go into your game and scroll about and go near the light sources to see if it works.

If it doesn't

-Try tweaking the code; the + ID number("light source")= loopindex "lighting" always seem to give me a hard time. Keep rearranging them 'till they work.

If it does work but the lighting seems too harsh or dim

-often you will find that the lighting is too bright from weak light sources. To solve this replace the - Set semi-transparency ratio("light") to Dynamic light("light")+Ambient light("light") with - Set semi-transparency ratio("light") to (Dynamic light("light")/(a number))+Ambient light("light")

-often you will find that the lighting only affect the screen when you are really close to a source. To solve this you need to alter the "- set amount of illimunation("light source") to light intensity("light source")/Distance from window centre("light source")" expression. You should divide the "Distance from window centre" value by a number (in brackets) or more ideally divide it by another alterable value of the light source (this could be named "projection distance"). You can also change the divide sign to a minus sign, but remember to make the value absolute (abs()) or the light sources will make the scene darker when they are far away.

8. This system usually doesn't work the way you want it to first time round so tweak it and tweak it 'till it does work the way you want it to. Although it doesn't light individual objects on the screen, the way it lights the screen on scrolling games where you would, for example, walk past a street lamp can look really convincing. Another trick is to slightly tint the picture used in the active picture object- different colours for different ambient moods:
-blue tint for night and day
-blue/turqoise tint for morning
-Reddish orange tint for evening
-red tint for mars

That's just about it... i think. Hope you find this useful. I've written this pretty much from memory so I have missed something or made a mistake, please post a comment.