Jump to content


Photo

Fade in/Fade out


  • Please log in to reply
10 replies to this topic

#1 Windsdrow

Windsdrow

    GMC Member

  • Validating
  • 303 posts

Posted 05 September 2010 - 12:00 AM

Hi there.I want to ask.For example I got one sprite with:

image_index 1
image_index 2

Is it possible to make 'Fade in' and 'Fade out' effect than I change that sprite image_index?

#2 st4k3r 4 lyf

st4k3r 4 lyf

    GMC Member

  • GMC Member
  • 114 posts

Posted 05 September 2010 - 12:19 AM

Hi there.I want to ask.For example I got one sprite with:

image_index 1
image_index 2

Is it possible to make 'Fade in' and 'Fade out' effect than I change that sprite image_index?

im afraid theres no function for that. :( but you could make the animated image like a fade effect if thats what you want.
  • 0

#3 skunkchop

skunkchop

    GMC Member

  • New Member
  • 381 posts

Posted 05 September 2010 - 12:30 AM

image_alpha controls transparency. image_alpha=1 means it is opaque(fully visible), image_alpha=0 means it is fully invisible, 0.5 would be half transparent, etc.
You can make an image fade in by making a code that keeps on increasing its alpha. FOR EXAMPLE:

In Create Event of object that you want to fade in:
image_alpha = 0

In Step Event:
if image_alpha != 1
image_alpha += 0.1

The image would become 10% more visible every frame, until it is fully visible. COOL EH!?
  • 2

#4 ChickenViking

ChickenViking

    GMC Member

  • New Member
  • 368 posts

Posted 05 September 2010 - 02:14 AM

I'm just guessing here, but to fade out again, won't you need to write

if image_alpha != 0
image_alpha -= 0.1

Edited by ChickenViking, 05 September 2010 - 02:14 AM.

  • 0

#5 skunkchop

skunkchop

    GMC Member

  • New Member
  • 381 posts

Posted 05 September 2010 - 02:26 AM

I'm just guessing here, but to fade out again, won't you need to write

if image_alpha != 0
image_alpha -= 0.1


Yes, but DO NOT put that in the same place.
If you have
if image_alpha != 0
image_alpha -= 0.1
in the same place as
if image_alpha != 1
image_alpha += 0.1
then the code will NOT WORK. This is because every frame, it will subtract AND add 0.1 image_alpha.

If what you want to do is make it fully fade in, then fully fade out, do this:

IN CREATE EVENT:
alarm[0] = 1 //activate alarm[0] in one frame

IN ALARM[0] EVENT:
if image_alpha != 1  //if it is not fully visible
{
image_alpha += 0.1  //make it 10% more visible
alarm[0] = 1  //repeat in 1 frame
}
else  //if it IS fully visible
if image_alpha != 0  //blah blah blah
{
image_alpha -= 0.1
alarm[0] = 1
}


NOTE: Do not leave things invisible, as they take memory. Make sure to add instance_destroy whenever something finishes fading out.

Edited by skunkchop, 05 September 2010 - 02:27 AM.

  • 0

#6 ChickenViking

ChickenViking

    GMC Member

  • New Member
  • 368 posts

Posted 05 September 2010 - 04:11 AM

Of course, but I was thinking the player can fade in when the room stars and fade out when the room ends. That way it can appear like he's stepped through a door, used a teleporter etc. :)
  • 0

#7 skunkchop

skunkchop

    GMC Member

  • New Member
  • 381 posts

Posted 05 September 2010 - 04:17 AM

Ahh, that's smart. I'll probably use that idea!
Tell me if you need any more help. :)
  • 0

#8 ChickenViking

ChickenViking

    GMC Member

  • New Member
  • 368 posts

Posted 05 September 2010 - 04:18 AM

The devil's in the details. B-)
  • 0

#9 regniwekim

regniwekim

    GMC Member

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

Posted 05 September 2010 - 04:22 AM

in the player's create event
image_alpha = 0;

in the step event
image_alpha += .1;
if image_alpha > 1 image_alpha = 1;

and in the room end event
image_alpha -= .1;

Edited by regniwekim, 05 September 2010 - 04:23 AM.

  • 0

#10 RocketLauncher3G

RocketLauncher3G

    Int. Game Programmer

  • GMC Member
  • 627 posts

Posted 05 September 2010 - 10:34 AM

Regniwekim, my guess is that it won't work like that. Since the room end event only occurs once, so the alpha will stay at 0.9, and won't decrease. My guess would be like so:
//room end event ;)
while (image_alpha > 0) { //as long as image_alpha is greater then 0, do the following:
  image_alpha -= 0.05; //subtract 0.05 from the image alpha
  screen_refresh(); //refreshes the screen with the new draw events
  screen_redraw(); //redraws the screen with the refreshed screen
}

I hope this works :)
  • 0

#11 Brother156

Brother156

    GMC Member

  • Validating
  • 498 posts

Posted 05 September 2010 - 03:06 PM

Or you could first fade out and then switch rooms. For example, in the player collision event with the door:

alarm[9]=1;

then in alarm[9]:

if (image_alpha>0)
{
image_alpha-=0.1;
alarm[9]=1;
}
else
{
room_goto_next();
}

that will fade the player out and then goto the next room...

Hope that helped! :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users