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 :: Day 4 :: Sprites

 

Text, backgrounds, what next?  Sprites, of course!  Here's another easy on for you.  So easy, in fact, I suspect that you'll figure it out just by looking at the comments.

 

// Includes
#include <PA9.h> // Include for PA_Lib
// Graphics Includes
// --- Sprites ---
#include "gfx/blue_ball.raw.c"
#include "gfx/blue_ball.pal.c"

// Function: main()
int main(int argc, char ** argv)
{
PA_Init(); // Initializes PA_Lib
PA_InitVBL(); // Initializes a standard VBL

//PA_LoadSplash(); // PA_Lib splash screen

PA_LoadPal(PAL_SPRITE1, blue_ball_Palette);
// PAL_SPRITE1 = top screen, sprite palette name
PA_LoadPal(PAL_SPRITE0, blue_ball_Palette);
// PAL_SPRITE0 = bottom screen, sprite palette name

PA_CreateSprite(1, // 1 = top screen
0, // Sprite number (0 to 127)
(void*)blue_ball_Bitmap, // Sprite name
OBJ_SIZE_32X32, // Sprite size
1, // 256 color mode
0, // Palette number
112, // X position (0-511)
80); // Y position (0-255)

PA_CreateSprite(0,0,(void*)blue_ball_Bitmap,OBJ_SIZE_32X32,1,0,112,80);

// Infinite loop to keep the program running
while (1)
{
PA_WaitForVBL();
}

return 0;
} // End of main()

 

Code Explanation

Again, this shouldn't be too tough to figure out.  Notice how we are still using PA_LoadPal(), we just pass it the sprite palette for each screen.

PA_CreateSprite(...);
Some things to note about this function:

  • There can only be up to 128 sprites per screen (This is a hardware limit.)  Note that I chose to put the sprite in the first slot (0).  If there had already been a sprite there, then I would have destroyed it.  

  • My sprite is 32x32 pixels so we use OBJ_SIZE_32X32.  

  • The palette number will always be 0 if you are in 256 color mode.  Otherwise, you can have up to 16 different 16 color palettes per screen to use for your sprites.  We'll probably come back to that concept later.

 

Download

Day4_Sprites.zip

 

Screenshot

Day1_Hello_World 

 

Last Update: 10/31/2005

 

Google
 
Web aaronrogers.com/nintendods

 

<<

HOME

>>