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:
Draw GUI:
Destroy:
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.
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);
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);
Code:
if (obj_menu_controller.state == menu_states.state_play) {
room_goto_next();
}