Pages: 1
  Print  
Author Topic: 2D Lighting  (Read 2548 times)
Offline (Male) hpg678
Posted on: September 29, 2017, 09:05:17 am

Member
Location: Barbados
Joined: Mar 2017
Posts: 283

View Profile Email
I've started a little project using 2D lighting. I actually wanted to do a shader effect casting light and shadows but discovered a far more simplistic way through a Youtube video.......at least for a 2D game.

The idea is to create a parent object that handles the alpha value of a child object so that the further the player if from it, that object alpha value becomes less than 0 whereby it darkens. The closer it is to the player, the object opacity rises to the point where it becomes visible.  The first screenshot shows this.



you can also control the color of the lighting you want by changing the 'color' value in the 'draw_sprite_ext' function. Notice that I place the 'obj_globalp' to be the parent of the wall object,  the grass tile and coin.

Another thing to note is the number "140'. this controls the radius of visibility of the relevant objects to the player. The smaller the value the smaller the radius and vice versa.

The original code worked in GameMaker 8 but didn't work in either versions of ENIGMA, so this is basically a rewrite of the original code.  I believe it can be helpful in a top down game, a maze game or probably something else like a day and night effect with some more tweaking. who knows.

Hope it been useful in some way.

Here a link to the source file in gmk format https://www.dropbox.com/s/aw4xycno5i0qw69/2D_Lighting_sample.gmk?dl=0
« Last Edit: September 29, 2017, 10:14:22 am by hpg678 » Logged
[compromised account]
Pages: 1
  Print