Trouble with fading in GUI [SOMEWHAT SOLVED]

Started by iamlowlikeyou, Fri 21/01/2011 11:12:20

Previous topic - Next topic

iamlowlikeyou

I'm using this code to fade in my GUI:
Code: ags

void SetTransparency(){
    gIconbar.Transparency = 100;
    int trans = gIconbar.Transparency;
    while (trans > 0) {
      trans--;
      gIconbar.Transparency = trans;
      Wait(1);
    }
  }


SetTransparency() is initiated when pressing the key that makes the GUI visible.
When I run the game and tries it out, the GUI remains "invisible", that is transparency =100 for some 5 seconds, and then become visible (trans = 0) all of a sudden...
Any ideas why this isn't working?

Gilbert

What colour depth is your game at?

Matti

#2
A while loop like this one:

Code: ags

    while (trans > 0) {
      trans--;
      gIconbar.Transparency = trans;
      Wait(1);
    }


..will stop all code from being executed until its finished. The transparency decreases until it reaches 0 and then the code finally has a chance to even show that change. It needs a moment due to the 100 wait commands.  You'd need an if instead of while.

Gilbert

I haven't tried but I doubt whether this is the problem. As the screen will be refreshed to show changes whenever a Wait() is used this should work.

iamlowlikeyou

#4
Quote from: Gilbet V7000a on Fri 21/01/2011 12:42:41
What colour depth is your game at?
My game is at 32 bit, so that shouldn't be the problem...

Quote from: Matti on Fri 21/01/2011 12:44:33
A while loop like this one:

Code: ags

    while (trans > 0) {
      trans--;
      gIconbar.Transparency = trans;
      Wait(1);
    }


..will stop all code from being executed until its finished. The transparency decreases until it reaches 0 and then the code finally has a chance to even show that change. It needs a moment due to the 100 wait commands.  You'd need an if instead of while.

Thanks, I'll try with an "if".
But why does it say "while" in the manual then ???

EDIT: When I change it to "if" it simply doesn't work - that is it just stays invisible...

Matti

Nah, Gilbet seems to be right. The while shouldn't cause any trouble. It's just that I thought I had that problem before, but I just tried it out and it worked fine.

Ultra Magnus

What do you have the while game is paused, GUIs should... setting as? Try setting it to display as normal.
I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

iamlowlikeyou

#7
Quote from: Ultra Magnus on Fri 21/01/2011 12:56:10
What do you have the while game is paused, GUIs should... setting as? Try setting it to display as normal.

If you mean "when player interface is disabled, GUIs should", then it's already set to normal.

Anyway, should I put the fade-in code in any specific section of the script, or should it work anywhere?

Ultra Magnus

I don't mean to sound bitter, cold, or cruel, but I am, so that's how it comes out.

I'm tired of pretending I'm not bitchin', a total frickin' rock star from Mars.

iamlowlikeyou

#9
Okay, so I tried to make it like this just to be absolutely sure;
Code: ags

void SetTransparency(){
    gIconbar.Transparency = 100;
    Wait(10);
    gIconbar.Transparency = 80;
    Wait(10);
    gIconbar.Transparency = 70;
    Wait(10);
    gIconbar.Transparency = 60;
    Wait(10);
    gIconbar.Transparency = 50;
    Wait(10);
    gIconbar.Transparency = 40;
    Wait(10);
    gIconbar.Transparency = 30;
    Wait(10);
    gIconbar.Transparency = 20;
    Wait(10);
    gIconbar.Transparency = 10;
    Wait(10);
    gIconbar.Transparency = 0;
  }


Still it just waits 2-3 seconds (the 100 gameloops) in which the GUI is invisible, and then it becomes Transparency = 0 at once.
It looks to me like it's not a scripting error since the "not visible/visible function" IS working, only all the inbetween-steps are not shown. But since my game is set to 32 bit color, I can't figure out what could cause this error?

EDIT: I just discovered that if I just put:
Code: ags

void SetTransparency(){
    gIconbar.Transparency = 50;
}

...it sets the transparency to 50 like it's supposed to, but as soon as I put:
Code: ags

void SetTransparency(){
    gIconbar.Transparency = 50;
    Wait(10);
    gIconbar.Transparency = 20;
}

...it simply waits for the 10 gameloops and then sets transparency to 20 at once. So it somehow seems to be the Wait command that makes some kind of glitch in my script?

Matti

Where did you put the script in? If it's in room_load or something, then that's the problem.

iamlowlikeyou

It's in the main script...

It's being called from a key press (but that's not important I guess, since it's the function itself that's acting weird).

Khris

I set the Iconbar's visibility in my test game to "Normally, initially on", copied the function from the very first post to my Script and assigned it to a key being pressed. Works absolutely flawlessly, fades right in.

Then I changed the game's color depth to 32bit and the GUI changed to be being a black box. It still fades in gradually, but I can't see the buttons any longer.
I deleted one of the buttons and changed the GUI's background color setting, now I can see that color fade in where the button was. Where the button's are supposed to be, the GUI is black.
Right-clicking one of the button images, copying it to the clipboard and importing it from there over itself fixes the not-being-displayed/black issue. After I did that to all iconbar buttons, I now have a GUI fading in nicely @ 32bit.

This doesn't solve your problem though. I'd try re-importing the background of the room, now that the game is set to 32bit.

iamlowlikeyou

#13
The GUI has no background, only background color and then some buttons.
I tried re-importing the room background, though I set the game to 32 bit color from the start (and should a room background have any effect on GUIs?), but it still makes the same error.

The fade-in code isn't supposed to be at any specific place in the script, right?

Khris

No, but it does make a difference from where it's called.
Calling it after a keypress will work fine (should).

The color depth of the room background sets the color depth of everything else; in earlier versions of AGS, setting the color depth to 16bit didn't do a thing if you didn't import a background for the room.

iamlowlikeyou

#15
I just tried it myself in an empty game, and here it works perfectly too.
*Sigh* I guess this is where the endless hunt for the bug begins...

UPDATE:
Finally for some reason beyond my knowledge I ended up taking the code into the same function that actually made the GUI visible, and then it worked flawlessly. Why I cannot say...
Of course this is a little inelegant, but it works.

SMF spam blocked by CleanTalk