|
|
|
|
|
|
|
Nintendo
DS Development Tutorial :: Day 3 :: BGs Tiled
|
|
|
|
Okay, so you now basically know how to do text output and get user input from the pad. Let's
move on to something that's also simple, yet quite powerful - displaying an
image on the screen(s).
|
|
|
// Includes #include <PA9.h> // Include for PA_Lib
// Graphics Includes // gfx2gba -fsrc -m -pBackground.pal -t8 Background.bmp #include "gfx/Background.map.c" #include "gfx/Background.raw.c" #include "gfx/Background.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_BG0, Background_Palette); PA_LoadPal(PAL_BG1, Background_Palette);
PA_LoadSimpleBg(1, 3, Background_Tiles, Background_Map, BG_256X256, 0, 1); PA_LoadSimpleBg(0, 3, Background_Tiles, Background_Map, BG_256X256, 0, 1);
// Infinite loop to keep the program running while (1) { PA_WaitForVBL(); }
return 0; } // End of main()
|
|
|
Code
Explanation
gfx2gba
-fsrc -m -pBackground.pal -t8 Background.bmp
gfx2gba is a simple program that converts a bitmap image
into code that can be displayed on the screen. I
won't go into too much detail on gfx2gba. I'll just
show you how I am converting my bitmap
backgrounds (and later sprites) into the proper format. Be
sure to check out the gfx2gba readme.txt
and you can look for newer versions (currently 0.13) here.
If you want more info on gfx2gba, check out my HAM Tutorials
starting here.
In this case, I am outputting to a source format file (.cpp),
creating a map of 8x8 pixel tiles, saving the palette as Background.pal,
and the input image is Background.bmp.
For more information on tile-based graphics, check out these sites:
http://www.nonoche.com/imaging/en/
Tile
Based Games FAQ
http://www.gamedev.net/reference/list.asp?categoryid=44
PA_LoadPal(PAL_BG0,
Background_Palette);
Loads a 256 color palette (which I created from the original bitmap
using gfx2gba).
PA_LoadSimpleBg(1,
3, Background_Tiles, Background_Map, BG_256X256, 1, 1);
Very easy way to load a background image to the screen.
Parameters:
screen, 0 = bottom, 1 = top
background, 0-3, 0 goes on top of 1 which goes on top of 2... (more on this later)
tiles, you'll notice this is defined in source\gfx\Background.raw.c
map, reference to the map, in this case it's in source\gfx\Background.map.c
size, in this case I created a 256x256 pixel bitmap, can be 256x512, 512x256, or 512x512
wraparound, does the BG wrap around? (not important in this case)
color_mode, 0 = 16 color mode, 1 = 256 color mode
Well, that's about it for today. Another easy example, I wonder when it's going to get difficult?
|
|
|
|
Download
Day3_BGs
Tiled.zip
|
|
|
|
Screenshot

|
|
|
|
Last Updated: 10/31/2005
|
|
|
|
|
|
|
|
|
|