Heroes of Loot Light system explained


I’ve been getting various questions and remarks on the “light system” I use in Heroes of Loot.. so I figure it would make for some good blog filling to talk about what and how and why.

For those who don’t know any of my code, let me just explain that I’m not a technically great coder.. I like to do simple code and just stuff that works and looks good. I’m more creative then technical, so keep that in mind cause this lighting stuff is really as simple and basic as it looks.

My engine renders the background using a simple tile-rendering. The dungeon tiles are 16×16, and the game runs in a low pixel-art-friendly resolution, I personally like to call it 160p :)

My lightning system is simply another tile-map I lay on top of the screen. The tiles in this map are 8×8, and the tiles are all black 8×8 tiles but with variations in the alpha transparency.

So if an area is fully lit, the alpha is 0, and it basically means I don’t render that light-map-tile saving some time.  In fully dark area’s the alpha is 255 and light-map-tile is fully rendered on top of the background, making it become black and covering the background fully.

This is a bit backwards as you can imagine, cause my light system will actually render fully lit area’s faster than fully dark area’s.. which is great, cause most of the action happens in the lit area’s on the screen.

This also means I can go crazy with light-sources, so bullets, flames, energy orbs, everything can create a little light area, and it will not cause any noticeable difference to the game speed, cause the calculations to make it light up are balanced out by the fact that I render a lot less pixels.

Creating the light is simply resetting the light-map every frame, and then changing the alpha values in a circle of a specific size around a specific point in the map. The result is a very rough, crude, and simple pixel-art style lighting system that doesn’t feel out of place in a pixel-art game likes Heroes of Loot :

Schermafbeelding 2013-05-06 om 17.31.47

Bookmark the permalink.