#143355 - koleslaw54 - Sat Oct 20, 2007 4:26 am
Alright, I just started using libnds last week and I'm making a quick breakout clone to learn about lots of different things. The only problem is that I can't find any good tutorials on using sprites, and I have a bug that doesn't make sense to me. I can't get sprites to show up on the screen, here's the relevant sections of my code...
Can anyone help me understand what's wrong?
Code: |
// Global copy of sprite attribute memory
SpriteEntry sprites[128]; // Copy our sprite to object attribute memory void updateOAM(void) { DC_FlushRange(sprites, 128 * sizeof(SpriteEntry)); dmaCopy(sprites, OAM, 128 * sizeof(SpriteEntry)); } // Turn off all 128 sprites the DS uses void initSprites(void) { int i; for(i = 0; i < 128; i++) { sprites[i].attribute[0] = ATTR0_DISABLED; sprites[i].attribute[1] = 0; sprites[i].attribute[2] = 0; sprites[i].attribute[3] = 0; } // A 16 Color Sprite - Uses Indexed color pallete SPRITE_PALETTE[17] = RGB15(31,31,25); SPRITE_PALETTE[18] = RGB15(31,30,12); SPRITE_PALETTE[19] = RGB15(31,29,3); SPRITE_PALETTE[20] = RGB15(31,25,0); sprites[0].attribute[0] = ATTR0_WIDE | 150; sprites[0].attribute[1] = ATTR1_SIZE_32 | 112; sprites[0].attribute[2] = ATTR2_PALETTE(1); // Draw the Rectangular Sprite 32x8 - Writing 4 pixels at a time u16 paddle[64] = { 0x0123, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4443, 0x4210, 0x1344, 0x4433, 0x3333, 0x3333, 0x3333, 0x3333, 0x3444, 0x4431, 0x2444, 0x4333, 0x2222, 0x2222, 0x2222, 0x2222, 0x3334, 0x4442, 0x4444, 0x4433, 0x3333, 0x3333, 0x3333, 0x3333, 0x3444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x2444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4442, 0x1344, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4431, 0x0123, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x3210 }; for(i=0;i<64;i++) SPRITE_GFX[i]=paddle[i]; updateOAM(); } void initVideo() { vramSetMainBanks(VRAM_A_MAIN_BG, VRAM_B_MAIN_SPRITE, VRAM_C_SUB_BG); videoSetMode(MODE_0_2D | DISPLAY_SPR_ACTIVE | DISPLAY_BG0_ACTIVE | DISPLAY_SPR_1D | DISPLAY_SPR_1D_BMP | DISPLAY_BG1_ACTIVE); // I'm using BG1 for background and BG0 for the console BG1_CR = BG_32x32 | BG_COLOR_16 | BG_MAP_BASE(0) | BG_TILE_BASE(1); BG0_CR = BG_MAP_BASE(31) | BG_TILE_BASE(4); } int main(void) { powerSET(POWER_ALL_2D); lcdMainOnBottom(); irqInit(); irqSet(IRQ_VBLANK, 0); initVideo(); initSprites(); while(1) { // Handle Input // swiWaitForVBlank(); updateOAM(); } |
Can anyone help me understand what's wrong?