We have allocated VRAM Bank F for holding our sprite graphics in a previous chapters. Bank F is 16KB big, so it can hold up to 512 16-color tiles.

We will load the 16x16 graphic into tiles 0->3.

First, make some definitions to where your going to load things. Also add a neat definition to translate tile numbers into VRAM addresses.
#define tiles_ball 0 // ball tiles (16x16 tile 0->3) #define tile2objram(t) (SPRITE_GFX + (t) * 16) |
Now DMA copy the tiles into VRAM (in your setupGraphics functions).
dmaCopyHalfWords( 3, gfx_ballTiles, tile2objram(tiles_ball), gfx_ballTilesLen );
|
We need to copy the palette to the sprite palette ram. The main engine's sprite palette is located at addresse 0x5000200->0x50003FF. The layout is the same as the BG one, with the first color of each 16 color palette transparent (and only color 0 is transparent in 256 color mode).
We will load our palette to the first 16-color sprite palette.

Add this definition to calculate an address in the sprite palette. SPRITE_PALETTE is the libnds definition for this region. Also add the palette index you will use.
#define pal2objram(p) (SPRITE_PALETTE + (p) * 16) #define pal_ball 0 // ball palette (entry 0->15) |
Now DMA copy the palette into the memory.
dmaCopyHalfWords( 3, gfx_ballPal, pal2objram(pal_ball), gfx_ballPalLen );
|
We are now ready to start adding sprites to the display.... In the next chapter!
| Previous: Alpha blending | Contents | Next: Displaying sprites |