Game Development Community

Changing Alpha with scripting.

by Joey Gutierrez · in Torque Game Builder · 01/13/2008 (12:06 pm) · 2 replies

Well I am trying to work on a game for my senior project. I know how to set up the Alpha under the edit tab so that something may appear more transparent. What I am wondering, though, is how can I change this alpha with scripting???

Which function would it be best to put this in, and how would it be written???

I've tried things like

'classname'.Alpha = "number";

and

%this.Alpha = number;

Any help will be appreciated.

#1
01/13/2008 (12:16 pm)
Use the setBlendAlpha() method. Here are a couple of Helper functions I wrote to fade things in and out. They may help you. Stick a breakpoint in there and see how they work.

function Fade(%object, %toAlpha, %timeMs, %deleteWhenDone)
{
   echo("Fade" SPC %object SPC %toAlpha SPC %timeMs SPC %deleteWhenDone);
   if (isObject(%object)) {
      if(%timeMs > $FADE::GRANULARITY)
      {
          %alpha = %object.getBlendAlpha();
          %updatesRemaining = %timeMs / $FADE::GRANULARITY;
          %alpha += (%toAlpha - %alpha) / %updatesRemaining;
          %object.setBlendAlpha(%alpha);
          schedule($FADE::GRANULARITY, 0, Fade, %object, %toAlpha, %timeMs - $FADE::GRANULARITY, %deleteWhenDone);
      }
      else
      {
          %object.setBlendAlpha(%toAlpha);
          
          if (%deleteWhenDone == true)
            %object.safeDelete();
          
      }     
   }
}
#2
01/13/2008 (12:17 pm)
*subscribing*