Transparency for Characters

Started by Mantra of Doom, Mon 12/01/2009 04:29:27

Previous topic - Next topic

Mantra of Doom

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.

Code: ags

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


I also even set the button's OnClick to
Code: ags

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.
"Imitation is the sincerest form of imitation."

Trent R

#1
Does your character's sprite have an alpha channel? That messes up transparency.


~Trent

[Edit]: I think 16-bit does work...
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

monkey0506

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.

Mantra of Doom

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.
"Imitation is the sincerest form of imitation."

Laukku

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);
}
You are standing in an open field west of a white house, with a boarded front door.
>WIN GAME
Congratulations! You just won! You got 0 out of 500 points.

Khris

Heh.

Code: ags
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.)

Mantra of Doom

Okay, with your help, I got it to work. Here is the code:

Code: ags

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
  }
}
"Imitation is the sincerest form of imitation."

Khris

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:
Code: ags
    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
    }

SMF spam blocked by CleanTalk