Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Tue 29/07/2003 19:49:02

Title: Slow Fade In\Out
Post by: on Tue 29/07/2003 19:49:02
Hi all,

I've found that using FadeOut(1) or FadeIn(1) is still very fast even though it is apparantly on the lowest speed. I want to use these slow fades for something like a title or introduction sequence. Is there anyway to get it to go slower?

thanks
Title: Re:Slow Fade In\Out
Post by: Scummbuddy on Wed 30/07/2003 00:41:05
If you want it slower, you could create a very large animation that would run over the whole screen, run the animation, then change rooms, and then reverse the animation.  since it would be a big animation, and not all that hard to make, it may be what you are looking for.
Title: Re:Slow Fade In\Out
Post by: Ben on Wed 30/07/2003 03:19:48
If your game is 256 colors, you could create two new functions (Credits to Dorcan for creating this script  :) )

function PaletteVariation(int r, int g, int b, int start, int end){
// This function is for the color balance
 J=start;
 while (J<=end) {
     pr[J]=palette[J].r;  //backup of the palette
       if (palette[J].r+r<0) palette[J].r=0; else
       if (palette[J].r+r>63) palette[J].r=63; else
       palette[J].r+=r;
     
     pg[J]=palette[J].g;
       if (palette[J].g+g<0) palette[J].g=0; else
       if (palette[J].g+g>63) palette[J].g=63; else
       palette[J].g+=g;
       
     pb[J]=palette[J].b;
       if (palette[J].b+b<0) palette[J].b=0; else
       if (palette[J].b+b>63) palette[J].b=63; else
       palette[J].b+=b;
           
     J++;
 }

 UpdatePalette();

 J=start; // restore the palette backup
 while (J<=end) {
     palette[J].r=pr[J];
     palette[J].g=pg[J];
     palette[J].b=pb[J];
     J++;
 }
}

function Fade(int oR, int oG, int oB, int R, int G, int B, int start, int end, int speed){
 nR=oR;
 nG=oG;
 nB=oB;
 
 while ((nR!=R) && (nG!=G) && (nB!=B)){
   if (R<oR) nR--; else nR++;
   if (G<oG) nG--; else nG++;
   if (B<oB) nB--; else nB++;
   PaletteVariation(nR, nG, nB, start, end);
   Wait(speed);
 }
}  

Then just import those functions in your script header and put this in your room script to fade in:

Fade(-256, -256, -256, 0, 0, 0, 0, 255, 4  );

And this to fade out:

Fade(0, 0, 0, -256, -256, -256, 0, 255, 4  );

You can change the 4 if that's still not the speed you want.

Of course, this is probably a bit more complicated than it needs to be. I'm sure a more experienced scripter could simplify it a bit more.. Also, this only works in 256 colors, so if you're using high color, you'll have to find another solution.. Like fading away a large object with SetObjectTransparency().

EDIT: Hmm.. That spell-check messed up the script. You'll have to change "are" to "r"  :P
Title: Re:Slow Fade In\Out
Post by: on Fri 01/08/2003 15:42:51
Thanks for the help guys!