#117174 - dannyboy - Fri Feb 02, 2007 1:43 am
Well, I decided to update to the newest ndslib, and I've got everything working except for this one thing. I got the complex_2d demo up and running and expanded it to getting more than one type of sprite working with the SPRITE_PALETTE_SUB. But when I try extended palettes they no longer work. The sprites just comes out black. Heres the relevent bits of code:
Code: |
#define NUM_SPRITES 20 vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE); void SetPaletteColours(u8 PaletteID, sImage Image) { int offset = PaletteID * 256; vramSetBankI(VRAM_I_LCD); // Open VRAM for writing palette for (int i = 0; i < 256; i++) { VRAM_I[offset + i] = Image.palette[i]; } vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE); } void LoadImage(unsigned char* pcxFile, int id) { int offset = id*32*16; // offset in memory for multiple sprites sImage Image; loadPCX(pcxFile, &Image); // load our pcx file into an image imageTileData(&Image); // tile it so it is useful as sprite data for(int i = 0; i < 32*16; i++) { SPRITE_GFX_SUB[offset + i] = Image.image.data16[i]; } SetPaletteColours(id, Image); // the following line is for the standard palette. If it is commented out then sprites // come out black. Otherwise they default to this palette. if (id == 0) { for (int i = 0; i < 256; i++) { SPRITE_PALETTE_SUB[i] = Image.palette[i]; } } } void LoadSprites() { LoadImage((u8*)two_pcx, 1); LoadImage((u8*)three_pcx, 0); initOAM(); // turn off sprites for(int i = 0; i < NUM_SPRITES; i++) { //random place and speed sprites[i].x = rand() & 0xFFFF; sprites[i].y = rand() & 0x7FFF; sprites[i].dx = (rand() & 0xFF) + 0x100; sprites[i].dy = (rand() & 0xFF) + 0x100; if(rand() & 1) { sprites[i].dx = -sprites[i].dx; } if(rand() & 1) { sprites[i].dy = -sprites[i].dy; } sprites[i].oam = &OAMCopySub[i]; sprites[i].gfxID = 0; if (i < 10) { sprites[i].gfxID = 1; } //set up our sprites OAM entry attributes sprites[i].oam->attribute[0] = ATTR0_COLOR_256 | ATTR0_SQUARE; sprites[i].oam->attribute[1] = ATTR1_SIZE_32; sprites[i].oam->attribute[2] = ATTR2_PALETTE(sprites[i].gfxID) | sprites[i].gfxID*32; } } |