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.

Graphics > chopped up sprites

#8136 - Foz - Wed Jul 02, 2003 6:33 pm

I recently created a 256 color sprite in Photoshop and saved it as a .PCX file. I then used Dovoto's pcx2gba to create the header. The output read a 64x64 sprite with 8 bits per pixel which was correct. I then used this file in a test program:
Code:

int main()
{
   u16 loop;
   u16* temp;

   SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);
   for(loop = 0; loop < 256; loop++)
      OBJPaletteMem[loop] = playerPalette[loop];

   InitializeSprites();

        sprites[0].attribute0 = COLOR_256 | SQUARE | ROTATION_FLAG | 50;   
        sprites[0].attribute1 = SIZE_64 | ROTDATA(0) | 120;                  sprites[0].attribute2 = 0;                     

   for(loop = 0; loop < 2048; loop++)      // 64x64 / 2 pixels at a time
          {
             OAMData[loop] = playerData[loop];
          }

        while(1)   //the main game loop
   {
      GetInput();
      RotateSprite(0, angle, zoom, zoom);
      WaitForVsync();
      CopyOAM();            }
}


Most of the code is gbajunkie's with some changes. Anyway, when I run Mappy VM the sprite appears 64x64 but it is all rearranged beyond recognition. Here is the CopyOAM function:
Code:

void CopyOAM()
{
   u16 loop;
   u16* temp;
   temp = (u16*)sprites;
   for(loop = 0; loop < 128*4; loop++)
   {
      OAM[loop] = temp[loop];
   }
}

I'm not sure if the problem is here or in the translation of the graphic with the pcx2gba program.[/code]

#8138 - niltsair - Wed Jul 02, 2003 6:47 pm

You have to convert your picture using another program because the pixels aren't arranged in the way you expect, for sprites, instead of being 64x64, the gba expect the sprite data to be divided in tiles

(Tile 00) (Tile 01) (Tile 02) (Tile 03) (Tile 04) (Tile 05) (Tile 06) (Tile 07)
(Tile 08) (Tile 09) (Tile 10) (Tile 11) (Tile 12) (Tile 13) (Tile 14) (Tile 15)
....

Where each tile are a 8x8 pixels block.

Anyway, there's probably an option for pcx2gba to output sprite format, and if not, you'll have to pick another converter.

#8146 - Foz - Thu Jul 03, 2003 12:54 am

Thanks niltsair. I used pcx2sprite and it worked fine. gbajunkie's tutorial says to use pcx2gba. He must have gotten them mixed up. I'll send him an email.