Re: clearifing something up with sprites
Posted: Fri Jan 09, 2009 9:50 pm
yes I knew that 

Professional toolchains, amateur prices
https://devkitpro.org/
Code: Select all
#include <nds.h>
#include "moon.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
// enable the main screen with background 0 active
videoSetMode(MODE_0_2D | DISPLAY_BG0_ACTIVE);
// map bank A for use with the background
vramSetBankA(VRAM_A_MAIN_BG);
// enable background 0 in 256 color mode with a 256x256 map
// BG_TILE_BASE changes the offset where tile data is stored
// BG_MAP_BASE gives the offset to the map data
BGCTRL[0] = BG_TILE_BASE(0) | BG_MAP_BASE(4) | BG_COLOR_256 | BG_BMP8_256x256;
// use dma to copy the tile, map and palette data to VRAM
// CHAR_BASE_BLOCK gives us the actual address of the tile data
// SCREEN_BASE_BLOCK does the same thing for maps
// these should match the BG_TILE_BASE and BG_MAP base numbers above
dmaCopy(moonPal,BG_PALETTE,moonPalLen);
dmaCopy(moonTiles,(void *)CHAR_BASE_BLOCK(0),moonTilesLen);
dmaCopy(moonMap,(void *)SCREEN_BASE_BLOCK(4),moonMapLen);
// finally, hang around in an infinite loop
// using swiWaitForVBlank here puts the DS into a low power loop
while(1) {
swiWaitForVBlank();
}
return 0;
}
Code: Select all
# Set the warning/log level to 3
-W3
# Tell grit to include a palette (the first index in it will be transparent)
-p
# Tile the image
-gt
# Set the bit depth to 4 (16 colors)
-gB4
Code: Select all
//loads the palette
dmaCopyHalfWords(DMA_CHANNEL, //0-3
fileNamePal, //grit generated
&SPRITE_PALETTE[0 * 16], // 0 = first palette, 16 = 16 colors
fileNamePalLen); //grit generated
//loads the "sprite"
dmaCopyHalfWords(DMA_CHANNEL,//0-3
fileNameTiles, //grit generated
gfx, //destination (oamAllocateGfx() will return a u16* you can use here)
fileNameTilesLen);//grit generated
Code: Select all
#include <nds.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
int i;
videoSetMode(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_SPRITE);
oamInit(&oamMain, SpriteMapping_1D_32, false);
dmaCopyHalfWords(DMA_CHANNEL, //0-3
fileNamePal, //grit generated
&SPRITE_PALETTE[0 * 16], // 0 = first palette, 16 = 16 colors
fileNamePalLen); //grit generated
//loads the "sprite"
dmaCopyHalfWords(DMA_CHANNEL,//0-3
fileNameTiles, //grit generated
gfx = oamAllocateGfx(oam, size, format);, //destination (oamAllocateGfx() will
fileNameTilesLen);//grit generated
while(1) {
oamSet(&oamMain, //main graphics engine context
0, //oam index (0 to 127)
0, 0, //x and y pixle location of the sprite
0, //priority, lower renders last (on top)
0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
SpriteSize_16x16,
SpriteColorFormat_256Color,
gfx, //pointer to the loaded graphics
-1, //sprite rotation data
false, //double the size when rotating?
false); //hide the sprite?
swiWaitForVBlank();
}
return 0;
}
Code: Select all
#include <nds.h>
#include "test.h"
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
videoSetMode(MODE_0_2D);
vramSetBankA(VRAM_A_MAIN_SPRITE);
oamInit(&oamMain, SpriteMapping_1D_32, false);
u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32, SpriteColorFormat_256Color);
dmaCopyHalfWords(3, testPal, &SPRITE_PALETTE[0 * 16], testPalLen); //grit generated
dmaCopyHalfWords(3,//0-3
testTiles, //grit generated
gfx, //destination (oamAllocateGfx() will
testTilesLen);//grit generated
while(1) {
oamSet(&oamMain, //main graphics engine context
0, //oam index (0 to 127)
0, 0, //x and y pixle location of the sprite
0, //priority, lower renders last (on top)
0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
SpriteSize_32x32,
SpriteColorFormat_256Color,
gfx, //pointer to the loaded graphics
-1, //sprite rotation data
false, //double the size when rotating?
false); //hide the sprite?
swiWaitForVBlank();
}
return 0;
}
Code: Select all
dmaCopyHalfWords(3, testPal, SPRITE_PALETTE, testPalLen);
Code: Select all
dmaCopy(testPal, SPRITE_PALETTE, testPalLen);