How to fade out text after a second in GameMaker

1.7k views Asked by At

In my game, if the player goes through a door, I would like to have text appear for one second and then fade out.

I'm using GameMaker:Studio 1.4

2

There are 2 answers

0
Arjo Nagelhout On

Create an object, for example obj_text, with the following events:

  • Create event:

    alpha = 1;
    fade_out = false;
    alarm[0] = 60; // Time in frames
    
  • Alarm 0 event:

    fade_out = true;
    
  • Step event:

    if (fade_out) {
        alpha -= 0.05;
    }
    
    if (alpha <= 0) {
        instance_destroy();
    }
    
  • Draw event:

    draw_set_alpha(alpha);
    draw_text(x, y, "You went through a door");
    draw_set_alpha(1);
    

When the player goes through a door, simply use instance_create(x, y, obj_text) to display the text.

0
SomeCoder On
  1. Create a new object for example "obj_text".
  2. Create event:

    count = 0
    alpha = 1
    delay = 1 // in seconds
    
  3. Step event:

    if (count == room_speed * delay) {
        alpha -= 0.05
        draw_set_alpha(alpha)
        if (image_alpha <= 0) {
            instance_destroy();
        }
    }
    else {
        count += 1
    }
    draw_text(x, y, "You went through a door")
    draw_set_alpha(1);
    

    When the player goes through the door you simply use

    instance_create( x, y, obj_text)
    

    to display the text.

You can change the value of delay to define how long the text should be shown until it starts to fade out.