• 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!

GML Problem with draw_set_alpha

B

Brainworm

Guest
Hey,
so, I made a menu for my game and in the beginning I just wanted to play a sound, when the player hits enter on a menu entry. So, for example, when the player has "Start Game" marked and he hits enter, it plays a sound and then starts the game. Problem was, there is no "sound_end" event or something, so since I had room_goto_next() right after the audio_play_sound() the sound was never played because the next room was loaded right away. I searched a bit arround and came to this Reddit thread:
https://www.reddit.com/r/gamemaker/comments/713txf/how_do_i_make_the_game_slowly_fade_to_black/
It is not about my specific problem but I thought the fade effect would add nice to it, So now I create another object, when the player hits enter, that plays the sound on create and after that draws a dark rectangle on the screen, so it slowly fades to black before starting the game.
The problem with the sound is now solved, but I have can observe a strange effect with the fading. When I hit enter, the whole screen fades to black and back to normal and than fades again to black, but slower, and then the game starts. Here is my code for the obj_fade_controller

Create:
Code:
alpha = 0;
fadeTime = 1.5 * room_speed;
audio_play_sound(Powerup_Pickup, 1, false);
Draw GUI:
Code:
if (alpha < 1) {

   alpha += 1/fadeTime; // alpha will reach 1 at set fade time

   if (alpha >= 1) {
       instance_destroy();
   }
}


draw_set_alpha(alpha);

draw_set_colour(c_black);

draw_rectangle(0,0,view_wport[0],view_hport[0],-1);
Destroy:
Code:
if (obj_menu_controller.state == menu_states.state_play) {
   room_goto_next();
}
I had to get rid of the draw_set_alpha(1) mentioned in the Reddit thread because otherwise the effect did not work at all. I log out alpha in the step event and it only adds up until the object is destroyed so I really do not understand the quick fade before the actual fade.
 

2Dcube

Member
You have to reset the alpha value again because it will be changed for everything else too.
The draw_set_alpha(1) has to be put after the stuff you want to draw with transparency. Like this:
Code:
draw_set_alpha(alpha);

draw_set_colour(c_black);

draw_rectangle(0,0,view_wport[0],view_hport[0],-1);

draw_set_alpha(1);
 
B

Brainworm

Guest
You have to reset the alpha value again because it will be changed for everything else too.
The draw_set_alpha(1) has to be put after the stuff you want to draw with transparency. Like this:
Code:
draw_set_alpha(alpha);

draw_set_colour(c_black);

draw_rectangle(0,0,view_wport[0],view_hport[0],-1);

draw_set_alpha(1);
Thank you, that actuallay fixed it!
I am not sure, why it did not work at all before, when I had the draw_set_alpha(1) already in the code. But I think, what happened was, that I could not see the rectangle before, because my background is black and it may have been to small, because I copy pasted it from the Reddit thread before and there the rectangle was set up with room_height and room_width, but I have a viewport set up, that stretches the whole game a lot. I switched the color to white and could see a small recangle, but I must have sorted out the
draw_set_alpha(1) already at this point, thinking it did not work with it or something. Whatever, now it works, thank you :).
 
R

RichJ

Guest
Problem was, there is no "sound_end" event or something
I ran into this too. There is a simple way around it.

put this in the create event for your menu

var len;
len = audio_sound_length(snd_menu_sound);

then when you select the start option have it run this instead of room_goto_next
alarm[0] = room_speed * len;

set the alarm event to do what you want after the sound.
 
B

Brainworm

Guest
I ran into this too. There is a simple way around it.

put this in the create event for your menu

var len;
len = audio_sound_length(snd_menu_sound);

then when you select the start option have it run this instead of room_goto_next
alarm[0] = room_speed * len;

set the alarm event to do what you want after the sound.
Nice, thank you!
 
Top