• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Game Mechanics Directional Player Lighting?

ZyKro

Member
How would you go about creating a system in which the player can only see a ray/cone of visible light in the direction they're facing?
I'm imagining something like this:

I plan on using this in a future game. I appreciate the help.
 

Attachments

Niels

Member
The easiest way is to make a surface that has a black/dark rectangle that covers the view/screen and use a cone shaped sprite to punch a hole in it with blend modes.
There are plenty tutorials on how to do this on YouTube.
 

NightFrost

Member
For a simple light cone effect, use of surface as suggested above is a good solution. If you want obstacles cast shadows within the cone, that's a more complex affair with ray casting. This article goes over the idea (not in GML).
 

ZyKro

Member
Thanks for the replies. I will look on YouTube and I will also check out that article as well.
 
R

Robert Russell

Guest
Hi, surfaces and Windows play very nicely together but surfaces and Android phones often seem to make an unhappy combination … have not played with this for a while so things may have improved, but I always found it killed the frame rate fairly fast, even when I followed the consensus about how to optimise things.

So, you can look at things the other way up. Make your entire environment dark, then dynamically construct a gpu alpha blending mask between this and a light version of your environment. The mask represents your torch light, The nice thing about this is you can add in fake height masks and light rays by adding and subtracting from the mask depending where you are in the room. The code is short but the explanation long because blending functions are mind bending to visualise .. some bits on my website rivingten.com.

Image below has some static lights in the arches and then a torch cone that moves about.

Regards,Rob.
 

Attachments

Top