Nintendo DS


Introduction


Version History

Day 1
Environment Setup

Links

WiFiMe

PA_Lib

Linux

Emulators

Downloads

Demos




NDS Magic Key MK2/MK3

   Hosted by
FrogNet


Document made with Nvu

 

Nintendo DS Development Tutorial :: Examples :: Splash Screen Effect

 

Here's an example of how to do a splash screen effect.  It's kind of a hack, but I think you'll get the idea.  Oh, and this code will run at a good speed on real hardware but quite slow in most emulators.

 

// Includes
#include <PA9.h> // Include for PA_Lib
// Graphics Includes
// gfx2gba -fsrc -m -pBackground.pal -t8 Background.bmp
#include "gfx/Splash1.map.c" #include "gfx/Splash1.raw.c"
#include "gfx/Splash1.pal.c"

// Function: main()
int main(int argc, char ** argv)
{
// Variables
s8 state = 0; // 0 = fade in; 1 = wait; 2 = fade out;
s8 counter = 0; // Just a counter
s8 bl = -32; // Brightness Level

PA_Init(); // Initializes PA_Lib
PA_InitVBL(); // Initializes a standard VBL

//PA_LoadSplash(); // PA_Lib splash screen

PA_LoadPal(PAL_BG0, Splash1_Palette);

PA_LoadSimpleBg(0, 3, Splash1_Tiles, Splash1_Map, BG_256X256, 0, 1);

// Infinite loop to keep the program running
while (1)
{
// Game States
switch (state) {
case 0: // Fade In
if (bl < 1) bl+=1;
if (bl == 0) state = 1;
break;
case 1: // Wait
counter+=1;
if (counter == 40) state = 2;
break;
case 2: // Fade Out
if (bl > -32) bl-=1;
if (bl == -32) state = 3;
break;
default:
break;
}

PA_SetBrightness(0, bl);

PA_WaitForVBL();
}

return 0;
} // End of main()

 

Code Explanation

switch(...)
This could have been a series of if/then's, but I like switch statements more.  The second  argument passed to PA_SetBrightness() is the brightness level and it ranges from -32 (black) to 32 (white).  I start out by setting it to -32 and then increment it to 0 (neutral) during the 'fade in' gamestate.  After pausing for a few seconds, control is then passed to the 'fade out' gamestate and the brightness level variable gets decremented back to -32.

PA_SetBrightness(screen, bright);
Sets the brightness level (-32 to 32) of screen (0 or 1).

 

Download

Splash_Screen

 

Screenshot

Day1_Hello_World

 

 

 

Google
 
Web aaronrogers.com/nintendods

 

<<

HOME

>>