gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Problems(Bug) using 16x16 sprites

#171293 - seven - Thu Nov 12, 2009 3:53 pm

Hello,

is there a known bug/problem using 16x16 sprites ?
i am trying to use 16x16 sprites on my project and i found myself having the following problem :

if for example i am trying to display more than one 16x16 sprites on the screen is being displayed the first allocated sprite as many times as the number of sprites that i am trying to display .

i have even tried this on the example "bitmap_sprites" from "Graphics/Sprites/bitmap_sprites/" .

note that i am using SpriteColorFormat_Bmp format, so if you change in that tutorial example the sprites size from 32x32 to 16x16 and the format for all to SpriteColorFormat_Bmp you will see 3 red sprites instead of the 1red, 1green, 1blue ..

does anyone know anything about this ?

i should mention that this problem i have only when i am using 16x16 or 8x16 etc .. not for 32x32 ..

Thanks.


Last edited by seven on Thu Nov 12, 2009 4:26 pm; edited 1 time in total

#171294 - seven - Thu Nov 12, 2009 3:59 pm

here would be the code from here but modified for 16x16 (if anyone is interested to check it out): http://www.devkitpro.org/libnds/a00007.html#a9

Code:
#include <nds.h>
#include <stdio.h>

//a simple sprite structure
//it is generally preferred to separate your game object
//from OAM
typedef struct 
{
   u16* gfx;
   SpriteSize size;
   SpriteColorFormat format;
   int rotationIndex;
   int paletteAlpha;
   int x;
   int y;
}MySprite;

int main() {
    //three sprites of differing color format
   MySprite sprites[] = {
      {0, SpriteSize_16x16, SpriteColorFormat_Bmp, -1, 15, 20, 15},
      {0, SpriteSize_16x16, SpriteColorFormat_Bmp, -1, 15, 20, 80},
      {0, SpriteSize_16x16, SpriteColorFormat_Bmp, -1, 15, 20, 136}
   };

   videoSetModeSub(MODE_0_2D);

   consoleDemoInit();
   
   //initialize the sub sprite engine with 1D mapping 128 byte boundary
   //and no external palette support
   oamInit(&oamSub, SpriteMapping_Bmp_1D_128, false);

   vramSetBankD(VRAM_D_SUB_SPRITE);
   
   //allocate some space for the sprite graphics
   for(int i = 0; i < 3; i++)
      sprites[i].gfx = oamAllocateGfx(&oamSub, sprites[i].size, sprites[i].format);
   
    dmaFillHalfWords(ARGB16(1,31,0,0), sprites[0].gfx, 16*16*2);
   dmaFillHalfWords(ARGB16(1,0,31,0), sprites[1].gfx, 16*16*2);
   dmaFillHalfWords(ARGB16(1,0,0,31), sprites[2].gfx, 16*16*2);

   //set index 1 to blue...this will be the 256 color sprite
   SPRITE_PALETTE_SUB[1] = RGB15(0,31,0);
   //set index 17 to green...this will be the 16 color sprite
   SPRITE_PALETTE_SUB[16 + 1] = RGB15(0,0,31);

   while(1) {
      for(int i = 0; i < 3; i++) {
         oamSet(
            &oamSub, //sub display
            i,       //oam entry to set
            sprites[i].x, sprites[i].y, //position
            0, //priority
            sprites[i].paletteAlpha, //palette for 16 color sprite or alpha for bmp sprite
            sprites[i].size,
            sprites[i].format,
            sprites[i].gfx,
            sprites[i].rotationIndex,
            true, //double the size of rotated sprites
            false, //don't hide the sprite
            false, false, //vflip, hflip
            false //apply mosaic
         );
      }
      swiWaitForVBlank();
      //send the updates to the hardware
      oamUpdate(&oamSub);
   }
   return 0;
}

#171298 - sverx - Thu Nov 12, 2009 4:50 pm

Looks like they're all sharing the same location in memory... check gfx* member.

#171301 - seven - Thu Nov 12, 2009 5:37 pm

sverx wrote:
Looks like they're all sharing the same location in memory... check gfx* member.


No, they're not using the same location in memory, already tested that .
But couldn't figured exactly why, and why this happens just for 16x16 sprites size .

#171303 - seven - Thu Nov 12, 2009 6:52 pm

"Looks like a bug in oamSet()
The gfx pointers are all 512 bytes apart as they should be, but the gfx Index in OAM is 0 for all three sprites."

Any advices on how could this be fixed ?

#171342 - headspin - Sat Nov 14, 2009 1:55 pm

Looks like a bug in libnds to me. Perhaps make a bug report on the devkitARM forums?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game