Game Mechanics Grid Based Lighting System

G

GamingWalrus

Guest
I recently followed along with the HeartBeast tutorial on random map generation, available here:

I was wondering if anyone knows how I could make a dynamic lighting system that would work with this grid-based tile world? I have seen quite a few tutorials, but they all require wall objects of some kind, that the tutorial doesn't use. Can anyone help me out with this?
 

Surgeon_

Symbian Curator
I would also recommend one of my own assets if you want more sophisticated lighting based on grids and tiles, and also a heavy lifting tool for lots of other things (like grid collision detection and auto-tiling).

For example, in the following two images there are no objects except for the light emitters and the player, all are tiles.

 

Genetix

Member
I imagine you could do this in a number of ways - but here is a quick theory on a simple way to do so...

You could have dark block the size of each grid cell that are always on screen in the viewable area of the player.

If the room was pitch black - all of these blocks would have full transparency. If the player is holding a torch, you could have any block withing a certain distance of the player have little to no transparency, and increase it as they get farther away from the player until they are fully dark.

This shouldn't be to taxing on the system performance wise either - you only need a handful of these blocks ever, they always follow the in game view and stay on screen, snapping to their correct grid placement.

If built right it could be pretty smooth, and look pretty good.

It wouldn't even be to hard to hide light behind walls and other objects - the blocks could do a line collision check between them and the player/lightsource for walls and other 'solid' objects - if a collision is found they are dark.
 

Surgeon_

Symbian Curator
@Genetix I'm sorry but that is a terrible idea. Imagine, even if your view was.something like 10x20 grid cells, you'd already have 200 active objects in the view. And that amount would grow exponentially with any enlargement of the view. Not even to mention that each one of these objects would do one collision line check per light source in the general area of the view. Put together, this would be a complete opposite of "not taxing to system performance" - a recipe for disaster.
 

Genetix

Member
Good points - it was a quick idea without delving to deep into the concept. I imagine you could accomplish the same effect using one instance of an object as control. Line collision may not be perfect, but if staggered out through multiple steps one at a time (nearest to furthest) it could be done without much of any performance hit.

I'm not a pro on lighting - just offering an alternative concept for someone to try out, and hopefully optimize.
 
Top