gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Fading

#40178 - Fatnickc - Fri Apr 15, 2005 6:44 pm

I've worked out how to fade out, but I can't work out how to fade back in!
Any ideas? I know this will have been asked before, but I have searched and have tried all the mthods used but none seem to work for me.

#40181 - poslundc - Fri Apr 15, 2005 6:55 pm

...

Have you tried doing the opposite of what you did to fade out?

Dan.

#40185 - Fatnickc - Fri Apr 15, 2005 7:32 pm

Yes, and It doesn't work! I first tried using the original author's FadeIn function, but it wouldn't work either.

#40187 - poslundc - Fri Apr 15, 2005 7:40 pm

If you are using the original author's FadeIn function, you'll have to ask the original author. None of us know what he/she did.

Dan.

#40188 - Fatnickc - Fri Apr 15, 2005 7:43 pm

I could always give you my fade-out function, and see if you could work it out?;).
Code:

void FadeIntoColor(u16 targetColor,u16* bmpPalette,int fadeSteps) {

   int readX, step, red,green,blue;
   u16 sourceColor;

   for (step=0;step<=fadeSteps ;step++ ){
      WaitForVsync();
step++;
 for(readX = 0; readX < 256; readX++) {
         
         sourceColor = bmpPalette[readX];
         red = ((REDVALUE(sourceColor) * (fadeSteps-step)) + (REDVALUE(targetColor) * step)) /fadeSteps;
         green = ((GREENVALUE(sourceColor) * (fadeSteps-step)) + (GREENVALUE(targetColor) * step)) /fadeSteps;
         blue = ((BLUEVALUE(sourceColor) * (fadeSteps-step)) + (BLUEVALUE(targetColor) * step)) /fadeSteps;

         paletteMem[readX] = RGB( red , green , blue );
      }
   }

}

I think that it may be an endless loop, not allowing the next function to happen, but I'm not sure.

#40191 - DekuTree64 - Fri Apr 15, 2005 7:49 pm

It should work fine if you change your outer loop from
Code:
for (step=0;step<=fadeSteps ;step++ )

to
Code:
for (step=fadeSteps ;step>=0;step-- )

Fade out backwards, just like Dan said.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku