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.

DS development > How to add Fading Effect? [solved]

#166581 - Emmanuel - Tue Feb 10, 2009 2:51 pm

I'm wanting to add a fade to black, and then from black to the background in the middle of my room changes... but I have no idea how to...

Any body has an idea?


Last edited by Emmanuel on Tue Feb 10, 2009 8:56 pm; edited 1 time in total

#166587 - dovoto - Tue Feb 10, 2009 5:55 pm

Emmanuel wrote:
I'm wanting to add a fade to black, and then from black to the background in the middle of my room changes... but I have no idea how to...

Any body has an idea?


http://nocash.emubase.de/gbatek.htm#lcdiocolorspecialeffects

Basically, you set the targets you want to darken, chose the darken mode, then use the BLDY register to darken it.

(gbatek names for these registers will be in next libnds release).

Code:
/*---------------------------------------------------------------------------------

   Simple console print demo, modified to fade to dark
   -- dovoto

---------------------------------------------------------------------------------*/
#include <nds.h>
#include <stdio.h>

//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
   touchPosition touch;

   int dark = 0;

   consoleDemoInit();  //setup the sub screen for printing


   iprintf("\n\n\tHello DS dev'rs\n");
   iprintf("\twww.drunkencoders.com\n");
   iprintf("\twww.devkitpro.org");

   //set the blend control register to target bg0 (default console uses bg 0 of sub display)
   // and the mode to fade to black.
   SUB_BLEND_CR = BLEND_SRC_BG0 | BLEND_FADE_BLACK;

   while(1) {

      touchRead(&touch);
      iprintf("\x1b[10;0HTouch x = %04i, %04i\n", touch.rawx, touch.px);
      iprintf("Touch y = %04i, %04i\n", touch.rawy, touch.py);

      scanKeys();

      if(keysHeld() & KEY_UP) dark++;
      if(keysHeld() & KEY_DOWN) dark--;
      
      swiWaitForVBlank();

      //dark is shifted else it will change too fast
      SUB_BLEND_Y = dark >> 4;
      
   }

   return 0;
}

_________________
www.drunkencoders.com