V
Vanthex
Guest
Hi guys,
I posted on gamemaker's reddit about a lighting system that I wanted that looks like this:
In the replies I received, one of them provided me help on the code which is this:
SCRIPT (scr_set_block_alpha):
Now we'll return an alpha value as low as 0 if there are no blocks above our block or as high as 1 if there are at least 4 blocks above our block. This decreases as there are less blocks, so 3 blocks above us returns 0.75, 2 blocks is 0.50, and so on...this gets the transparency we want for our darkness.
Next, we should head into the Create Event for the block and set our transparency using the custom script right there.
CREATE EVENT:
All we have to do now is draw our block sprite and draw it again in black, but with the transparency value we calculated in the variable alpha.
DRAW EVENT:
Now the lighting works, but how do I make it so that it constantly updates when I create or destroy an instance? Do I need to create new events?
I posted on gamemaker's reddit about a lighting system that I wanted that looks like this:
In the replies I received, one of them provided me help on the code which is this:
SCRIPT (scr_set_block_alpha):
Code:
///scr_set_block_alpha()
var a = 0;
for (var i = 1; i <= 4; i++) {
if (place_meeting(x, y - (sprite_height * i), obj_block)) {
a += 1;
}
}
if (a > 0) {
a = (a * 25) / 100;
}
return a;
Next, we should head into the Create Event for the block and set our transparency using the custom script right there.
CREATE EVENT:
Code:
alpha = scr_set_block_alpha();
DRAW EVENT:
Code:
//Draw self
draw_self();
//Draw darkness
draw_sprite_ext(sprite_index, image_index, x, y, 1, 1, 0, c_black, alpha);