Fading an Entire Scene to Black
by Doug Linley · in Torque Game Builder · 07/01/2006 (9:59 am) · 2 replies
Can anyone point me to information on fading an entire scene to black? So far, the only fading information I can find revolves around the fade in gui control.
Thanks!
Thanks!
#2
07/05/2006 (9:34 am)
Alternatively you can use a set of functions likefunction t2dSceneObject::fadeToColor(%this, %time, %red, %green, %blue, %inc)
{
// store the starting color
%this.startColorBeforeFade = %this.getBlendColor();
// grab the starting colors
%startRed = getWord(%this.startColorBeforeFade, 0);
%startGreen = getWord(%this.startColorBeforeFade, 1);
%startBlue = getWord(%this.startColorBeforeFade, 2);
// this will allow you to pass in a target color as "0.5 0.5 0.5" as well as "0.5, 0.5, 0.5"
if(getWord(%red, 2) !$= "")
{
%inc = %green;
%green = getWord(%red, 1);
%blue = getWord(%red, 2);
%red = getWord(%red, 0);
}
// if our target colors and our present colors are the same then we need to do nothing
if((%startRed == %red) && (%startGreen == %green) && (%startBlue == %blue))
return;
// if we are already doing a color change then cancel it out
if(isEventPending(%this.colorFadeSchedule))
cancel(%this.colorFadeSchedule);
// how many time incriments do we want
if(%inc $= "" || %inc < 1 || %inc > 100)
%inc = 10;
// divide out what each time inc will be
%timeInc = (%time * 100) / %inc;
// get the different between starting and ending colors
%redDiff = %red - %startRed;
%greenDiff = %green - %startGreen;
%blueDiff = %blue - %startBlue;
// get the ammount we must inc each color each scheduled change
%redInc = %redDiff / %inc;
%greenInc = %greenDiff / %inc;
%blueInc = %blueDiff / %inc;
// call the color change
%this.fadingColor(%inc, %timeInc, %redInc, %greenInc, %blueInc);
}
function t2dSceneObject::fadingColor(%this, %inc, %timeInc, %redInc, %greenInc, %blueInc, %count)
{
// init the count if not specified
if(%count $= "")
%count = 0;
// grab the current color
%color = %this.getBlendColor();
// divide up the colors and inc them
%red = getWord(%color, 0) + %redInc;
%green = getWord(%color, 1) + %greenInc;
%blue = getWord(%color, 2) + %blueInc;
// set the new colors
%this.setBlendColor(%red, %green, %blue);
// inc the count
%count++;
// if the count is less than the planned incs then schedule this to be called again
if(%count < %inc)
%this.colorFadeSchedule = %this.schedule(%timeInc, "fadingColor", %inc, %timeInc, %redInc, %greenInc, %blueInc, %count);
}
Torque Owner Doug Linley