Windows fade in text

mmmm guys I'm a beginner at GML when I try to make fade in text I made a variable called:
GML:
text_alpha = 0;
then the same variable but in a step event:
GML:
text_alpha += 0.009;
in the draw event I write:
GML:
draw_set_alpha(text_alpha)
and for some reason it shows up instantly like the text_alpha is set to 1 I know this stupid ;-;
 
Last edited:

scorpafied

Member
in create event
alpha = 0;

in step event
if (alpha < 1) { alpha += 0.009; }

in draw event
// you need to use a draw text function that applies the alpha for it to work
draw_text_colour(room_width/2, room_height/2, "Test",c_white,c_white,c_white,c_white,alpha)
 
well... I did what you write but it doesn't work when I put a timeline,
I put a variable in the timeline
GML:
show_text = true;
in the object create event
GML:
show_text = false;
in draw event
GML:
if(show_text = true){
draw_text_color(x,y,"test",c_white,c_white,c_white,c_white,alpha)
}
the fade only works without the timeline.
 
I suspect that it isn't working because show_text isn't true. You could use draw_text(x, y, show_text); to find out. I seldomly ever use timelines, so I looked in the documentation and found the following information:

GML:
// This assigns the instance running the code a time line indexed in the variable "global.tl" if that time line exists.
global.tl = YOUR_TIMELINE_NAME_HERE;

if timeline_exists(global.tl) {
    timeline_index = global.tl;
    }

// This checks to see if the instance is running a time line, and if it is not then it resets the assigned time line to start at the first moment and then starts it.
if !timeline_running {
    timeline_position = 0;
    timeline_running = true;
    }
Are you sure that the timeline is running? If there are other events in it, do they seem to work?

One last thing you could try is using global.show_text and see if that gives you a different result.

I hope this helps or that someone more knowledge-able comes along soon. Good luck, my friend.
 

scorpafied

Member
well... I did what you write but it doesn't work when I put a timeline,
I put a variable in the timeline
GML:
show_text = true;
in the object create event
GML:
show_text = false;
in draw event
GML:
if(show_text = true){
draw_text_color(x,y,"test",c_white,c_white,c_white,c_white,alpha)
}
the fade only works without the timeline.
the issue is in the create event youve set the boolean variable to false. but the alpha is only applied to text if its true. set it to true and it will do the fade.
 

Slyddar

Member
If you are wanting the text to fade in after a certain time, use an alarm rather than the timeline.

You could do it like this:
Set up your variables.
Code:
//create event
alpha = 0;
alpha_inc = 0.009;
//setting fade in time to 5 seconds
alarm[0] = room_speed * 5;

Alarm[0] needs to be created and you have to add some text to it for it to work
Code:
//alarm 0
//fade in timer

The step event we increment the alpha value only if the alarm has counted down.
Code:
//step event
if alpha < 1 and alarm[0] < 0 alpha += alpha_inc;

Finally you can set the alpha and then draw_text the text.
Code:
//draw event
draw_set_alpha(alpha);
draw_text(room_width/2, room_height/2, "My Text");
draw_set_alpha(1);
 
Top