Making the screen black when player died

F

FiftyFive

Guest
Hello i m working on something. When the character falls off the map, the screen will turn black and the game will restart.
(i am begginer so can u guys explain me slowly. Thanks)

DRAW GUI event:
GML:
draw_set_color(c_black);
draw_set_alpha(image_alpha);

if(obj_oyuncu.y > room_height){
image_alpha += 0.05;

if(image_alpha == 1)
   {
       game_restart();

   }
}
else
{
    image_alpha -= 0.05;
    if(image_alpha == 0)
    {
    instance_destroy();
    }
}

draw_rectangle(0,0, view_wport*2,view_hport*2,false);
draw_set_alpha(1);
 
So... are you trying to restart the room when the screen fades to black, then fade out once restarted?

You could start your room with a fade out, so every time you fall out of the map and the screen is black you'll fade in, then restart to a fade out:
GML:
///create event
ALPHA = 1;

//step event
if obj_oyuncu.y > room_height
&& ALPHA >= 1
    room_restart();

///draw gui event
draw_set_color(c_black);
if obj_oyuncu.y < room_height
{
    if ALPHA > 0
        ALPHA -= 0.05;
}
else
{
    if ALPHA < 1
        ALPHA += 0.05;
}
draw_set_alpha(ALPHA);
draw_rectangle(0, 0, room_width, room_height, false);
draw_set_alpha(1);

draw_set_color(c_white);
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
GML:
if(image_alpha == 1)
   {
       game_restart();
   }
}
else
{
    image_alpha -= 0.05;
    if(image_alpha == 0)
    {
    instance_destroy();
    }
}
I feel like I should point out that this code in GameMaker (and pretty much any programming language) will generally not work... Using == means you are looking for an EXACT match between two values. However image_alpha (and most values in GameMaker) are what are called "floating point numbers", which means that 1 may actually 1.0000000000000067. This in turn means that image_alpha may never be exactly 1. All checks like this should be done using <> symbols instead, for example:
GML:
if (image_alpha >= 1)
{
game_restart();
}
 // OR

if (image_alpha <= 0)
{
instance_destroy();
}
I'm pretty sure that just making those changes would have your code working correctly. :)

I'll also leave this link here, as it explains nicely what exactly is going on: https://floating-point-gui.de/
 
Top