GUI Transparency property not fading with timers. Broken?

Started by AGD2, Mon 04/11/2013 10:05:59

Previous topic - Next topic

AGD2

I'm not exactly sure where the most appropriate place to post this is, so I figured I'd post it here. It seems a relatively simple issue but I'm not sure if I'm overlooking something obvious or have stumbled across a strange bug!

The AGS manual entry for the GUI Transparency property displays the following code as an example for how to make a GUI fade out:

Quote from: AGS Manual
int trans = gInventory.Transparency;
while (trans < 100) {
  trans++;
  gInventory.Transparency = trans;
  Wait(1);
}

will gradually fade the INVENTORY GUI out until it is invisible.

It also says "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."

Yet, I discover that if I put the above code (or similar) into a custom FadeGUIOut() function and then later call that function, the GUI transparency doesn't fade at all. It fact, I never see the GUI visibly appear on the screen. The GUI in question is a 640x400-sized black rectangle. The Background Image for the GUI is an imported, black 640x400 image sprite with no alpha channel. The GUI's X and Y coordinates are 0/0 so that the GUI appears at the top left corner of the screen and should completely cover the entire 640x400 game window when it's visible.

So, I also tested it by putting the following code in the custom FadeGUIOut() function instead, but got exactly the same result:

Quote
gBlack.Visible=true;
gBlack.SetPosition(0, 0);
gBlack.Transparency=0;
int trans = 0;

trans=5; gBlack.Transparency=trans; Wait(1);
trans=10; gBlack.Transparency=trans; Wait(1);
trans=20; gBlack.Transparency=trans; Wait(1);
trans=30; gBlack.Transparency=trans; Wait(1);
trans=40; gBlack.Transparency=trans; Wait(1);
trans=50; gBlack.Transparency=trans; Wait(1);
trans=60; gBlack.Transparency=trans; Wait(1);
trans=70; gBlack.Transparency=trans; Wait(1);
trans=80; gBlack.Transparency=trans; Wait(1);
trans=85; gBlack.Transparency=trans; Wait(1);
trans=90; gBlack.Transparency=trans; Wait(1);
trans=95; gBlack.Transparency=trans; Wait(1);
trans=100; gBlack.Transparency=trans; Wait(1);

gBlack.Transparency=100;

I then tried adding the above code directly into the "After FadeIn" script of a room file, and still experienced the same issue. But if I replace the above code in the "After FadeIn" script (or FadeGUIOUt() function) with this below, then it works. Go figure...

gBlack.Visible=true;
gBlack.Transparency=50;

I seem to recall using this method in the past and it used to work fine. I will also mention that it works works fine if using a character instead of a GUI with the same code.

So what's up here? Am I missing something incredibly obvious?

Khris

Quote from: AGD2 on Mon 04/11/2013 10:05:59It fact, I never see the GUI visibly appear on the screen.
This is the problem. If a GUI, with its Transparency set to 0, and Visibility to true still doesn't appear on the screen, the problem lies somewhere else.
Also note that you don't need a black image; leave the image set to 0 and simply set black as the background color.

You say if you manually call gBlack.Transparency = 50; it works. So it sounds like you're never actually calling your function.

You can also try this:
Code: ags
void FadeTo(this GUI*, int target, int speed) {
  int t = this.Transparency;
  if (speed == 0) {
    this.Transparency = target;
    return;
  }
  int step = 1;
  if (target < t) step = -1;
  int cnt;
  while (t != target) {
    t += step;
    this.Transparency = t;
    if (speed > 0) Wait(speed);
    else {
      cnt--;
      if (cnt == speed) {
        Wait(1);
        cnt = 0;
      }
    }
  }
}

(negative speed fades slow)

Tested with a 32-bit color game, works just fine.

AGD2

Ah, I've pinpointed the problem now. It has nothing to do with the code at all!

Basically, the gBlack GUI was set to "Normal, Initially On" and the "When interface disabled, GUIs should" setting was set to "Be Hidden". To fix the problem, I had to set the gBlack GUI to "Always Visible" in order to make it show up and start fading. Sneaky little detail.

Cheers for the code, though. That's a much more efficient way of handling things. :)

SMF spam blocked by CleanTalk