Legacy GM Fading out Text > Fading in Text

M

Murr_

Guest
Okay this was bugging me for 2 days straight and i have a grasp of it, but can't seem to really fix it. What i want to do is fade in the text(_image_0_alpha += 0.1) and display the text for a set amount of time (Alarm) then it fades out (_image_0_alpha -= 0.1) and displays another string of text fading in after the first one displayed.

This is my code i'm working with right now.
oINTROtalk_speech
Code:
///CREATE_EVENT
time_shown = 30;
end_shown = 20;
_image_0_alpha = 0;
_image_1_alpha = 0;
Code:
///BEGIN_GUI_DRAW EVENT
draw_text_ext_colour(192, 176, "'Un-Spoily Samper Text'", 40, 950, c_purple, c_white, c_white, c_purple, _image_0_alpha);

if (alarm[0] == -1) { <--- When room starts, begins alarm, and sets first text +0.1 until 1 or over 1
   alarm[0] = time_shown;
   _image_0_alpha += 0.1;
}

if (_image_0_alpha >= 1) { <--- Checks if first text is over 1 or 1 and -0.1 continuously until 0 or negative. This doesn't work for some apparent reason.
   _image_0_alpha -= 0.1;
}

if (_image_0_alpha <= 0) { <---- This checks if the first text equals to 0 and sets the second text alpha +0.1 until it gets to 1
   _image_1_alpha += 0.1;
   draw_text_ext_colour(192, 176, "'Another Un-Spoily samper text'", 40, 950, c_purple, c_white, c_white, c_purple, _image_1_alpha);
}
When i try to check to see if the first text is less than or equal to zero and try to set the second texts alpha + continuously. But it doesn't seem to work. It just keeps the first string alpha visible. Can someone help me with this? Its a pretty big step forward if i finish this problem quickly.
 

obscene

Member
if (_image_0_alpha >= 1) { <--- Checks if first text is over 1 or 1 and -0.1 continuously until 0 or negative. This doesn't work for some apparent reason.
_image_0_alpha -= 0.1;
}

As soon as it equals 0.9 it's NOT going to be greater or equal to 1 so it's going to stop decreasing.
 
M

Murr_

Guest
if (_image_0_alpha >= 1) { <--- Checks if first text is over 1 or 1 and -0.1 continuously until 0 or negative. This doesn't work for some apparent reason.
_image_0_alpha -= 0.1;
}

As soon as it equals 0.9 it's NOT going to be greater or equal to 1 so it's going to stop decreasing.
So it would be, if (_image_0_alpha <= 0) ?
 

obscene

Member
Personally I think your entire approach is a little off. First you want to figure out how to make one line fade in and fade out....

Code:
if fade_in
{
  image_alpha+=.01
  if image_alpha==1
  {
    fade_in=false;
    hold=120;
  }
}
else if hold
{
  hold-=1
  if hold==0 fade_out=true;
}
else if fade_out
{
  image_alpha-=.01
  if image_alpha==0
  {
    fade_out=false;
    line_complete=true;
  }
}

if line_complete
{
  // Reset
  text=newtext
  fade_in=true;
  line_complete=false;
}
It's simpler to just use easy-to-read variables you can turn on and off throughout the process to make sure the code follows exactly where you want it to go.
 
Last edited:
P

Paolo Mazzon

Guest
Okay this was bugging me for 2 days straight and i have a grasp of it, but can't seem to really fix it. What i want to do is fade in the text(_image_0_alpha += 0.1) and display the text for a set amount of time (Alarm) then it fades out (_image_0_alpha -= 0.1) and displays another string of text fading in after the first one displayed.
Let me stop you right there, you don't need anything besides a single alarm to pull this one off. You know that the total span of the text being drawn will be time frames, and you know that fade in and fade out should be fade frames (These are variables I will refer to in a moment). Firstly, you set the alarm to the total span of time that the text will be drawn (disregarding alpha fades), then you calculate the alpha based on how far along you are in the alarm. Here is some pseudo code to demonstrate this
Code:
if (alarm[0] > time - fade)
    draw_set_alpha(1 - (alarm[0] - (time - fade)) / fade);
else if (alarm[0] < fade)
    draw_set_alpha(alarm[0] / fade);

draw_text(x, y, text);
draw_set_alpha(1);
And by the way, there needs only to be a comment in the alarm to make sure the alarm actually counts down. Since you want more text after this one is done, just set the new text in the alarm and restart it.

EDIT: Fixed a small bug in my code.
 
Last edited by a moderator:
D

Daquaris Chadwick

Guest
Hello,

Just gonna point out that you never updated the alpha. draw_set_alpha(). Paolo has a quick idea if you want to change your code. The code that is below should be the fix to your problem. I used clamp because if you ever wanted it to be faster you can do that and you dont have to check if it is greater than 1 because it clamps it for you. Also, I want to point out to always update your alpha when you want to change the alpha as well as place everything you updated in the draw event back to its origin so you dont run into runtime error because your alpha is still 0 or etc.

Code:
fade_amount = 0.1;
draw_set_alpha(_image_0_alpha);
draw_text_ext_colour(192, 176, "'Un-Spoily Samper Text'", 40, 950, c_purple, c_white, c_white, c_purple, _image_0_alpha);

if (alarm[0] == -1) { <--- When room starts, begins alarm, and sets first text +0.1 until 1 or over 1
   alarm[0] = time_shown;
   _image_0_alpha = clamp(fade_amount, 0, 1);
}

if (_image_0_alpha == 1) { <--- Checks if first text is over 1 or 1 and -0.1 continuously until 0 or negative. This doesn't work for some apparent reason.
   _image_0_alpha = clamp(-fade_amount, 0, 1);
}

if (_image_0_alpha == 0) { <---- This checks if the first text equals to 0 and sets the second text alpha +0.1 until it gets to 1
   _image_1_alpha = clamp(fade_amount, 0, 1);
   draw_set_alpha(_image_1_alpha);
   draw_text_ext_colour(192, 176, "'Another Un-Spoily samper text'", 40, 950, c_purple, c_white, c_white, c_purple, _image_1_alpha);
}

draw_set_alpha(1);
This should work. If there are any error in this feel free to report them back and i'll fix them immediately. This is all dry code hehe.
 
P

Paolo Mazzon

Guest
I'm afraid your method uses unnecessary variables and clock cycles. Why would you use that giant block of code just to fade in and out text when I just proved it can be done in 4 lines of code (I tested mine by the way). You can do the fade out with those 4 lines I have, and in the alarm you can change the text. It is both more efficient and more readable.
 
M

Murr_

Guest
Personally I think your entire approach is a little off. First you want to figure out how to make one line fade in and fade out....

Code:
if fade_in
{
  image_alpha+=.01
  if image_alpha==1
  {
    fade_in=false;
    hold=120;
  }
}
else if hold
{
  hold-=1
  if hold==0 fade_out=true;
}
else if fade_out
{
  image_alpha-=.01
  if image_alpha==0
  {
    fade_out=false;
    line_complete=true;
  }
}

if line_complete
{
  // Reset
  text=newtext
  fade_in=true;
  line_complete=false;
}
It's simpler to just use easy-to-read variables you can turn on and off throughout the process to make sure the code follows exactly where you want it to go.
I understand the concept of this. After each variable is met to its specific value, it will begin its code structure as shown. But, i don't understand where this would be more efficient at...what i mean is if you were going to set the variables yourself (CREATE_EVENT)what what would you set them as? And if you were going to execute this whole code block should it be in the DRAW_GUI? And for the text=new_text in the STEP_EVENT?
 
M

Murr_

Guest
Let me stop you right there, you don't need anything besides a single alarm to pull this one off. You know that the total span of the text being drawn will be time frames, and you know that fade in and fade out should be fade frames (These are variables I will refer to in a moment). Firstly, you set the alarm to the total span of time that the text will be drawn (disregarding alpha fades), then you calculate the alpha based on how far along you are in the alarm. Here is some pseudo code to demonstrate this
Code:
if (alarm[0] > time - fade)
    draw_set_alpha(1 - (alarm[0] - (time - fade)) / fade);
else if (alarm[0] < fade)
    draw_set_alpha(alarm[0] / fade);

draw_text(x, y, text);
draw_set_alpha(1);
And by the way, there needs only to be a comment in the alarm to make sure the alarm actually counts down. Since you want more text after this one is done, just set the new text in the alarm and restart it.

EDIT: Fixed a small bug in my code.
I don't know if it would be a problem. But if my time is 30 - fade 0.1 and the ALARM is -1. Wouldn't that be false?And not entirely true to the comment?
 
P

Paolo Mazzon

Guest
I don't know if it would be a problem. But if my time is 30 - fade 0.1 and the ALARM is -1. Wouldn't that be false?And not entirely true to the comment?
The time variable should be the amount of time the text is drawn; eg time = room_speed * SECONDS_ACTIVE;. Fade should be the amount of time the fade in/out takes in frames like the time.
 
M

Murr_

Guest
The time variable should be the amount of time the text is drawn; eg time = room_speed * SECONDS_ACTIVE;. Fade should be the amount of time the fade in/out takes in frames like the time.
Wait how would you stop an alarm from repeating itself from doing a same code action in a code block, and move on with another?
 
P

Paolo Mazzon

Guest
Wait how would you stop an alarm from repeating itself from doing a same code action in a code block, and move on with another?
I'm assuming you mean how do I switch the text, and that is simple. Make a ds_list or array of all the things you want to fade in/out, then every alarm increase the current displayed text by 1, and if it's at max, stop.
Code:
// Create
text = ds_list_create();
ds_list_add(text, "This would be the first thing display");
ds_list_add(text, "The second");
ds_list_add(text, "The third");
currentIndex = 0;

time = room_speed * SECONDS;
fade = room_speed * SECONDS;

alarm[whatever] = time;

// Alarm[whatever]
currentIndex++;
if (currentIndex == ds_list_size(text) {
    // Quit
} else {
    alarm[whatever] = time;
}
Then, you would of course just draw the text "text[|currentIndex]"
 
D

Daquaris Chadwick

Guest
I'm afraid your method uses unnecessary variables and clock cycles. Why would you use that giant block of code just to fade in and out text when I just proved it can be done in 4 lines of code (I tested mine by the way). You can do the fade out with those 4 lines I have, and in the alarm you can change the text. It is both more efficient and more readable.
Hello,

I was fixing his code to make it work and for him to understand his errors. Buuuut, as i said in the post, yours is quicker. So...yeh.
-Godspeed
 
Top