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.

Beginners > Sprite display problem...

#115350 - markfgilmore - Mon Jan 15, 2007 1:33 pm

Bit of a newbie error I guess, but I've had a good look and can't figure out what I'm doing wrong.

Anyhow, the below code should display the background (a fetching orange number), and the sprites (a white square and a black sqaure). But the sprites aren't on show. So any help with what I'm doing wrong would be appreciated.

Thanks!

Code:
#include "gba.h"
#include "bg.h"
#include "bship.h"
#include "wship.h"

void InitializeSprites(void);
void CopyOAM(void);

OAMEntry sprites[128];

int main()
{

   u16 loop;

   SetMode(MODE_4 | BG2_ENABLE | OBJ_ENABLE | OBJ_MAP_1D);

   for(loop = 0; loop < 256; loop++) {
   OBJ_PaletteMem[loop] = bshipPalette[loop];
   }

   for(loop = 0; loop < 256; loop++) {
   OBJ_PaletteMem[loop] = wshipPalette[loop];
   }

   for (loop = 0; loop < 256; loop++) {
      BG_PaletteMem[loop] = bgPalette[loop];
   }

   for (loop = 0; loop < (120*160); loop++) {
      FrontBuffer[loop] = bgData[loop] ;
   }

   memcpy( (u16 *)0x06014000, &bshipData, sizeof(bshipData) );
   memcpy( (u16 *)0x06014100, &wshipData, sizeof(wshipData) );

   sprites[0].attribute0 = COLOR_256 | SQUARE | 64;
   sprites[0].attribute1 = SIZE_64 | 64;
   sprites[0].attribute2 = 512;

   sprites[1].attribute0 = COLOR_256 | SQUARE | 128;
   sprites[1].attribute1 = SIZE_64 | 128;
   sprites[1].attribute2 = 512 + 8;

   while(1)
   {
      WaitForVsync();
      CopyOAM();
   }

   return 0;

}

void InitializeSprites(void)
{
   u16 loop;
   for(loop = 0; loop < 128; loop++) {
      sprites[loop].attribute0 = 160;
      sprites[loop].attribute1 = 240;
   }
}

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



Edit: I should of also added that there are no warnings at complie time.

#115371 - sgeos - Mon Jan 15, 2007 5:48 pm

No OBJ palette?

-Brendan