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 10 :: Mosaic

 

Whew, yesterday's tutorial was neat, if not a little too overwhelming, so let's do something easy.  If you 've ever played any of the Super Mario Bros 2 on the Super NES, then you'll definitely be familiar with the mosaic effect - a kind of zooming/blurring transition effect.

Here's a good website with more information on mosaic.

 

// Includes
#include <PA9.h> // Include for PA_Lib
// Graphics Includes
// *** Backgrounds ***
// gfx2gba -fsrc -m -pBackground.pal -t8 Background.bmp
#include "gfx/Background.map.c"
#include "gfx/Background.raw.c"
#include "gfx/Background.pal.c"
// *** Sprites ***
// gfx2gba -D -fsrc -pSprites.pal -t8 Person.bmp
#include "gfx/Person.raw.c"
#include "gfx/Sprites.pal.c"


// Function: main()
int main(int argc, char ** argv)
{
// Variables
u16 Mosaic_X = 0;
u16 Mosaic_Y = 0;
u32 vbl_count = 0;

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

//PA_LoadSplash(); // PA_Lib splash screen

// Setup top screen
PA_LoadPal(PAL_SPRITE1, Sprites_Palette);
PA_CreateSpriteEx(1,0,(void*)Person_Bitmap,OBJ_SIZE_64X64,
1,0,0,1,0,0,0,0,112,64);

// Setup bottom screen
PA_LoadPal(PAL_BG0, Background_Palette);
PA_LoadSimpleBg(0, 3, Background_Tiles,
Background_Map, BG_256X256, 0, 1);
PA_EnableBgMosaic(0, 3);

// Infinite loop to keep the program running
while (1)
{
++vbl_count; // Increment the VBL counter

PA_UpdatePad(); // Check for input

// Check for input every 10 VBLs
if (vbl_count%10==0) {
Mosaic_X = Mosaic_X + Pad.Held.Right - Pad.Held.Left;
Mosaic_Y = Mosaic_Y + Pad.Held.Up - Pad.Held.Down;
}

// Reset mosaic to 0
if (Pad.Held.Start) Mosaic_X = Mosaic_Y = 0;

// Set the mosaic on the background
PA_SetBgMosaicXY(0, Mosaic_X, Mosaic_Y);
PA_SetSpriteMosaicXY(1, Mosaic_X, Mosaic_Y);

PA_WaitForVBL();
}

return 0;
} // End of main()

 

Code Explanation

Mosaic_X, Mosaic_Y
Mosaic can be applied horizontally or vertically so we are using these two variables to store the amount of mosaic.

PA_CreateSpriteEx(...)
This is the same as how we've used it before, except that we pass it a 1 (the 7th parameter from the end) to enable mosaic on this sprite.

PA_LoadSimpleBg(...)
This is also basically the the same as in previous examples.  The only thing we need to worry about here is the number we picked for this background.  In this case it was the 3rd background (on the bottom screen).

PA_EnableBgMosaic(0, 3);
This takes two parameters, the screen and the background number.

Mosaic_X = Mosaic_X + Pad.Held.Right - Pad.Held.Left;
Mosaic_Y = Mosaic_Y + Pad.Held.Up - Pad.Held.Down;
This is a really lazy way of updating the amount of mosaic applied to the sprite and background based on user input.

if (Pad.Held.Start) Mosaic_X = Mosaic_Y = 0;
I hope this makes sense to you.  If the Start button is pressed, the horizontal and vertical mosaic effect gets reset to none (0).

PA_SetBgMosaicXY(0, Mosaic_X, Mosaic_Y);
Notice that the first parameter is the screen - not the background number.  This will apply the amount of mosaic to all backgrounds with mosaic enabled on the (bottom) screen.

PA_SetSpriteMosaicXY(1, Mosaic_X, Mosaic_Y);
Notice that the first parameter is the screen - not the background number.  This will apply the amount of mosaic to all sprites with mosaic enabled on the (top) screen.

 

Download

Day10_Mosaic

 

Screenshot

Day1_Hello_World

 

Last Update: 10/31/2005

 

Google
 
Web aaronrogers.com/nintendods

 

<<

HOME

>>