• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Tile Alpha?

V

Victor Wolf

Guest
So I'm working on a game where the player is navigating a maze. The maze is lit when you hold spacebar and unlit when not. The enemies are drawn to you when the light is on.

I'm trying to do this with image alphas for now (trying to avoid lighting while I'm still a beginner).

It's working fine but I'd like to make it take a second to go all the way dark, so it will be more visually pleasing. Right now I'm just drawing a black rectangle over the tile layers when spacebar is not held. Is there a way to actually change the alpha of the tiles themselves? And if so, can I do it gradually?

If not, is there a way I can make the rectangle's alpha decrease before it disappears completely?

Thanks
 

Perseus

Not Medusa
Forum Staff
Moderator
As far as I'm aware, changing the alpha of individual tiles or the entire tilemap is currently not possible. But manipulating the alpha of the rectangle should be rather easy and a better practice to some extent. Use a variable to store the alpha value for drawing the rectangle. Using the Step event, keep decreasing it by a small amount when the spacebar is held down until it is equal to 0. When the spacebar is not being held down, keep increasing it until it is equal to 1.

Code:
if (keyboard_check(vk_space)) {
   rect_alpha = max(rect_alpha - 0.01, 0);
}
else {
   rect_alpha = min(rect_alpha + 0.01, 1);
}
Using draw_set_alpha(), set the drawing alpha to rect_alpha prior to drawing the rectangle.
 
V

Victor Wolf

Guest
Thanks! I'll try that out.
EDIT: Works great, thanks again. A little tweaking and it'll be perfect.
 
Last edited by a moderator:
Top