Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mantra of Doom on Mon 12/01/2009 04:29:27

Title: Transparency for Characters
Post by: Mantra of Doom on Mon 12/01/2009 04:29:27
In my game, I have a character that can turn "invisible". The sequence that should happen when a button is clicked is that a short animation should play and the character should quickly fade to be semi-transparent. The problem is though that I'm not quite sure how to fade the character to 50%. The code in the manual (below) just makes the character stand there for 3 seconds and then disappears. I'm not sure how to change this code to suit my needs when this doesn't really work.


int trans = cEgo.Transparency;
while (trans < 100) {
  trans++;
  cEgo.Transparency = trans;
  Wait(1);
}


I also even set the button's OnClick to

cEgo.Transparency=50;


But clicking on the button does nothing, though setting the value to 100 makes the character disappear. I know I'm missing something simple... but I can't work out what. Any help would be appreciated.
Title: Re: Transparency for Characters
Post by: Trent R on Mon 12/01/2009 05:04:53
Does your character's sprite have an alpha channel? That messes up transparency.


~Trent

[Edit]: I think 16-bit does work...
Title: Re: Transparency for Characters
Post by: monkey0506 on Mon 12/01/2009 05:43:51
Further, what color depth is your game. It definitely won't work at 8-bit, and I'm not 100% sure about 16-bit off the top of my head.
Title: Re: Transparency for Characters
Post by: Mantra of Doom on Mon 12/01/2009 13:25:09
Duh, my character did have an alpha channel in one frame. Now the transparency works properly, but I'm still not sure how to stop the fade at 50. Maybe it's just a little too early in the morning right now.
Title: Re: Transparency for Characters
Post by: Laukku on Mon 12/01/2009 14:13:03
Quote from: MantraofDoom on Mon 12/01/2009 13:25:09
Duh, my character did have an alpha channel in one frame. Now the transparency works properly, but I'm still not sure how to stop the fade at 50. Maybe it's just a little too early in the morning right now.

Here is a quick suggestion (untested)  :)

int trans = cEgo.Transparency;
while ((trans < 100) && (trans <50)) {
  trans++;
  cEgo.Transparency = trans;
  Wait(1);
}
Title: Re: Transparency for Characters
Post by: Khris on Mon 12/01/2009 16:06:50
Heh.

int trans = cEgo.Transparency;
while (trans < 50) {
  trans++;
  cEgo.Transparency = trans;
  Wait(1);
}


(If trans is smaller than 50, it's always also smaller than 100.)
Title: Re: Transparency for Characters
Post by: Mantra of Doom on Tue 13/01/2009 02:39:27
Okay, with your help, I got it to work. Here is the code:


function btnInv_OnClick(GUIControl *control, MouseButton button) //turn invisible button
{
  if (invisible==false)//Is the character already invisible?
  {
    //Play animation & set view
    int trans = cEgo.Transparency;
    while (trans < 51)
    {
      trans++;
      cEgo.Transparency = trans;
      Wait(1);
      cEgo.Transparency=50;
    }
    invisible=true; //Turns on invisible variable.
  }
  else //If is already invisible, character turns back to normal
  {
    int transoff = 50;
    while (transoff > 0)
    {
      transoff--;
      cEgo.Transparency = transoff;
      Wait(1);
    }
    invisible=false;   //Resets invisible variable
  }
}
Title: Re: Transparency for Characters
Post by: Khris on Tue 13/01/2009 13:31:38
Since the code is blocking, you don't need the invisible variable.
Just check if the character's transparency is 50 or 0.

I also think that the first loop should look like this:
    while (trans < 50)    // last loop at 49, trans is 50 at the end
    {
      trans++;
      cEgo.Transparency = trans;
      Wait(1);
      // cEgo.Transparency=50;  // why this line inside the loop? if you needed it, it would have to go after it
    }