Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dualnames on Wed 25/07/2007 21:59:22

Title: How to fade a Gui in and out
Post by: Dualnames on Wed 25/07/2007 21:59:22
I've been trying a lot. I want to make sort of a credits part. Where something is faded in then after a sec it's faded out. If it can be done through a credits module please redirect me to it.
Title: Re: How to fade a Gui in and out
Post by: monkey0506 on Wed 25/07/2007 22:01:26
Well since you specifically asked about a GUI, you could use the GUI.Transparency (http://americangirlscouts.org/agswiki/GUI_functions_and_properties#GUI.Transparency) property...which actually gives (in the manual) an example of how fading could be achieved....
Title: Re: How to fade a Gui in and out
Post by: Dualnames on Wed 25/07/2007 22:05:12
I've tried it.
The GUI is completely fade d out at the beggining(before fade in)
gGui1.Transparancy=100;
The fade out  works.

int trans = gGui1.Transparency;
while (trans < 100) {
  trans++;
  gGui1.Transparency = trans;
  Wait(2);
}

The fade in should be like

int trans = gGui1.Transparency;
while (trans != 0) {
  trans--;
  gGui1.Transparency = trans;
  Wait(2);
}

But it's not working.
Title: Re: How to fade a Gui in and out
Post by: monkey0506 on Wed 25/07/2007 22:25:20
How exactly does it "not work"? Is it not running all the way? Is there no visible change to the transparency? Simply saying it doesn't work is rather vague which makes the problem hard to diagnose.
Title: Re: How to fade a Gui in and out
Post by: Khris on Wed 25/07/2007 22:58:24
FYI, one doesn't need a variable.

  while (gGui1.Transparency<100) {
    gGui1.Transparency++;
    Wait(2);
  }
  Wait(80);
  while (gGui1.Transparency>0) {
    gGui1.Transparency--;
    Wait(2);
  }


This probably won't solve the problem, though.
Title: Re: How to fade a Gui in and out
Post by: Ashen on Wed 25/07/2007 23:15:18
Actually, I think you DO need the variable. Whenever I've tried changing GUI.Transparancy directly in the past, it just locks up (GUI doesn't fade in/out and it's basically on a permenant Wait). The manual says:
Quote
Some rounding is done internally when the transparency is stored -- therefore, if you get the transparency after setting it, the value you get back might be one out. Therefore, using a loop with gInventory.Transparency++; is not recommended as it will probably end too quickly.
I guess something similar is at work?

So you might need the variable but as monkey said, we need a bit more information on what exactly is/isn't happening. For the record, I tried the fadein code you posted and it works perfectly.
Title: Re: How to fade a Gui in and out
Post by: Dualnames on Wed 25/07/2007 23:42:49
It opens the gui without fading it then it closes it.
Title: Re: How to fade a Gui in and out
Post by: Ashen on Wed 25/07/2007 23:54:17
What colour depth is your game?
Title: Re: How to fade a Gui in and out
Post by: on Thu 26/07/2007 00:03:10
Ashen is right, changing the GUI.Transparency directly doesn't work. You need a variable to change and pass over. You don't need to define the same int trans two times, though. Define it once, later just use it.

Quote from: Dualnames on Wed 25/07/2007 22:05:12
int trans = gGui1.Transparency;
while (trans != 0) {
  trans--;
  gGui1.Transparency = trans;
  Wait(2);
}

I took your code and tried it out in a 16bit game, Dual. Believe it or not, if you replace the !=0 with a >0, it works. Sounds a bit strange- not equal shouldn't be much different from "larger than".
Possibly a quirk in AGS?
Title: Re: How to fade a Gui in and out
Post by: Ashen on Thu 26/07/2007 00:08:38
It works fine for me with '!= 0' - although I'd use '>', personally. It's the 'in a 16-bit game' part that I was getting at. Transparency doesn't work in 256 colour games (I think Lone Case 1 was 256? Can't tell with LC2, but if it is that's the problem right there.)
Title: Re: How to fade a Gui in and out
Post by: on Thu 26/07/2007 00:37:57
It should be the 16bit issue then. To clarify, I used the >0 instantly, out of habit, and when it worked, I thought to have found the error and thus posted "to replace !=".
Sorry for the foggy conclusion.
Title: Re: How to fade a Gui in and out
Post by: Shane 'ProgZmax' Stevens on Thu 26/07/2007 01:31:11
Might also be the Wait delay being too little for you to notice the fade, especially if you have a really fast machine.  Try Wait(10) or even Wait(20) just to make sure it's working before reducing it.
Title: Re: How to fade a Gui in and out
Post by: Dualnames on Thu 26/07/2007 03:29:13
It is 16 bit color game.
Title: Re: How to fade a Gui in and out
Post by: on Thu 26/07/2007 13:00:07
Did you try out the new code, as suggested by Ashen and myself, and did you try a longer delay, as suggested by ProgZ?