I want to have an image fade in and out using the draw event
Moving Drawings and alpha
Started by SuperBlackMan, May 08 2012 02:35 PM
5 replies to this topic
#1
Posted 08 May 2012 - 02:35 PM
#2
Posted 08 May 2012 - 02:45 PM
Create event:
Step event:
Draw event:
This will fade objects own sprite in and out repeatedly.
increase_var_alpha = true; var_alpha = 0;
Step event:
if(increase_var_alpha == true) {
var_alpha += 0.05;
if(var_alpha >= 1) increase_var_alpha = false;
}
else {
var_alpha -= 0.05;
if(var_alpha <= 0) increase_var_alpha = true;
}Draw event:
draw_sprite_ext(sprite_index, 0, x, y, 1, 1, 0, c_white, var_alpha);
This will fade objects own sprite in and out repeatedly.
#3
Posted 08 May 2012 - 03:08 PM
I like this lol. But Is there a way to where it can fade in then stay visible for like 5 secs, then fade out?
#4
Posted 08 May 2012 - 03:33 PM
Change that true / false thing to a number... 0, 1, 2, or 3. Then
Edit - Oh, you don't even have to change it to a number... just change it to this:
if(increase_var_alpha==1){
var_alpha += 0.05;
if(var_alpha >= 1){
increase_var_alpha=2;
}
}
else if(increase_var_alpha==0){
var_alpha -= 0.05;
if(var_alpha <= 0){
increase_var_alpha=3;
}
}
else{
if(alarm[0]==-1){
alarm[0]=room_speed*5;
}
}And then in alarm[0]if(increase_var_alpha==2){
increase_var_alpha=0;
}
else if(increase_var_alpha==3){
increase_var_alpha=1;
}That makes it fade in, wait 5 seconds, fade out, wait 5 seconds, fade in, etc.Edit - Oh, you don't even have to change it to a number... just change it to this:
if(increase_var_alpha == true and alarm[0]==-1) {
var_alpha += 0.05;
if(var_alpha >= 1) alarm[0]=room_speed*5;
}
else if(increase_var_alpha == false and alarm[0]==-1){
var_alpha -= 0.05;
if(var_alpha <= 0) alarm[0]=room_speed*5;
}And in alarm[0],if(increase_var_alpha == true) {
increase_var_alpha = false;
}
else {
increase_var_alpha = true;
}
Edited by dannyjenn, 08 May 2012 - 03:39 PM.
#5
Posted 08 May 2012 - 04:38 PM
Create event:
Step event:
Draw event:
Here you go, it now waits 5 seconds, in a cleaner way than danny's.
Danny's will also wait 5 seconds when it's faded out, I assume you do not want this.
Additionally, you must include something in alarm[0] so it will run, so I suggest putting in a code block with a comment so you know why it's there.
This is, however, my experience of it. Let me know if it works otherwise.
increase_var_alpha = true; var_alpha = 0;
Step event:
if(alarm[0] == -1) {
if(increase_var_alpha == true) {
var_alpha += 0.05;
if(var_alpha >= 1) {
increase_var_alpha = false;
alarm[0] = 5 * room_speed;
}
}
else {
var_alpha -= 0.05;
if(var_alpha <= 0) increase_var_alpha = true;
}
}Draw event:
draw_sprite_ext(sprite_index, 0, x, y, 1, 1, 0, c_white, var_alpha);
Here you go, it now waits 5 seconds, in a cleaner way than danny's.
Danny's will also wait 5 seconds when it's faded out, I assume you do not want this.
Additionally, you must include something in alarm[0] so it will run, so I suggest putting in a code block with a comment so you know why it's there.
This is, however, my experience of it. Let me know if it works otherwise.
Edited by Jobo, 08 May 2012 - 04:39 PM.
#6
Posted 08 May 2012 - 05:19 PM
Wow Thanks guys.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











