Jump to content


Photo

Moving Drawings and alpha


  • Please log in to reply
5 replies to this topic

#1 SuperBlackMan

SuperBlackMan

    GMC Member

  • GMC Member
  • 102 posts

Posted 08 May 2012 - 02:35 PM

I want to have an image fade in and out using the draw event
  • 0

#2 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2405 posts
  • Version:GM:Studio

Posted 08 May 2012 - 02:45 PM

Create event:
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.
  • 0

#3 SuperBlackMan

SuperBlackMan

    GMC Member

  • GMC Member
  • 102 posts

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?
  • 0

#4 dannyjenn

dannyjenn

    GMC Member

  • GMC Member
  • 2072 posts
  • Version:Mac

Posted 08 May 2012 - 03:33 PM

Change that true / false thing to a number... 0, 1, 2, or 3. Then
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.

  • 0

#5 Jobo

Jobo

    No neurons left today

  • GMC Member
  • 2405 posts
  • Version:GM:Studio

Posted 08 May 2012 - 04:38 PM

Create event:
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.

  • 0

#6 SuperBlackMan

SuperBlackMan

    GMC Member

  • GMC Member
  • 102 posts

Posted 08 May 2012 - 05:19 PM

Wow Thanks guys.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users