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 > Another sprite problem

#10113 - Phil Hale - Wed Aug 27, 2003 10:58 am

I'm have problems displaying sprites. Ever another sprite is displayed correctly. Sprites 0, 2, 4, and 6 work fine, and sprites 1, 3, and 5 do not, plus there is a 'artifact' in the top left of the screen. I have initialised the sprites to an off screen position so I have no idea why the artifact appears.

Heres the code (I have been following gbajunkies tutorials so thats where most of the code is from):

Code:
#include "sprite.h"
#include "gba.h"
#include "dispcnt.h"
#include "sprites\palette.h"
#include "sprites\ball.h"
#include "sprites\bat.h"
#include "sprites\block1.h"
#include "sprites\block2.h"
#include "sprites\block3.h"
#include "sprites\block4.h"
#include "sprites\block5.h"


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

  SetMode(MODE_1 | OBJ_ENABLE | OBJ_MAP_1D);

  for(loop = 0; loop < 256; loop++)   
    OBJPaletteMem[loop] = palette[loop];

  InitializeSprites();

   sprites[0].attribute0 = COLOR_256 | SQUARE | 142;     
   sprites[0].attribute1 = SIZE_8 | 11;
   sprites[0].attribute2 = 0;     
                    
   for(loop = 0; loop < 32; loop++)       {
     OAMData[loop] = ballData[loop];
   }
      
   sprites[1].attribute0 = COLOR_256 | WIDE | 147;     
   sprites[1].attribute1 = SIZE_16 | 107;              
   sprites[1].attribute2 = 2;                          

    for(loop = 32; loop < 160; loop++)       {
      OAMData[loop] = batData[loop-32];
    }
      
  sprites[2].attribute0 = COLOR_256 | WIDE | 35;     
  sprites[2].attribute1 = SIZE_16 | 12;              
  sprites[2].attribute2 = 10;                          

   for(loop = 160; loop < 288 ; loop++)       {
     OAMData[loop] = block1Data[loop-160];
   }
   
   sprites[3].attribute0 = COLOR_256 | WIDE | 35;     
   sprites[3].attribute1 = SIZE_16 | 56;              
   sprites[3].attribute2 = 18;                          

   for(loop = 288; loop < 416 ; loop++)       {
      OAMData[loop] = block2Data[loop-288];
   }

   sprites[4].attribute0 = COLOR_256 | WIDE | 35;     
   sprites[4].attribute1 = SIZE_16 | 102;              
   sprites[4].attribute2 = 26;                          

   for(loop = 416; loop < 544 ; loop++)      {
     OAMData[loop] = block3Data[loop-416];
   }

   sprites[5].attribute0 = COLOR_256 | WIDE | 35;     
   sprites[5].attribute1 = SIZE_16 | 147;              
   sprites[5].attribute2 = 34;                          

   for(loop = 544; loop < 672 ; loop++)                          {
      OAMData[loop] = block4Data[loop-544];
   }

   sprites[6].attribute0 = COLOR_256 | WIDE | 35;     
   sprites[6].attribute1 = SIZE_16 | 192;              
   sprites[6].attribute2 = 42;                          

   for(loop = 672; loop < 800 ; loop++)                          {
      OAMData[loop] = block5Data[loop-672];
   }

  while(1)   //the main game loop
  {
    WaitForVsync();      
    CopyOAM();         
   }
}

The first sprite is 8x8 and the rest are 32x8. I have swapped TALL and WIDE in sprite.h so they are the correct way round.

Can anyone tell me what I have done wrong??

#10179 - yaustar - Fri Aug 29, 2003 1:52 am

is it possible to post the rom image?

Also waht tool did you use to convert the images?
_________________
[Blog] [Portfolio]

#10196 - Phil Hale - Fri Aug 29, 2003 11:37 am

I used devotos pcx2sprite, which I'm pretty sure is the right program
How do I post the rom image?

#10221 - yaustar - Sat Aug 30, 2003 3:05 am

upload to some webspace and post a link to it...

and yes, that is the right tool
_________________
[Blog] [Portfolio]

#10645 - Master Mofo - Thu Sep 11, 2003 3:02 pm

Sorry for not going through your code rightnow, I do not have the Compiler . But I promise to compile it when I go home.

but till that time try this:
MAke sure that your calculations of the Loop variable are correct. you see 256 Color sprites take the double ammount of bytes the 16 Color ones take. for example a SQUARE 8x8 16 Col sprite occupies 32 bytes in the Char memory. While an 8x8 256 Col sprite occupies 32*2 bytes. (Twice the tiles). So your loop must be from 0 to 32 for the 256 sprite. If you know this already ignore what I have said. So your problem may be the Data arrays. You may have converted them the wrong way. MAke sure your data is defined as an u16 array instead of an U8.

- Try displaying Sprites one at a time. First make sure that the ball sprite is correctly displayed. after that add the 2nd sprite and so on.
_________________
"You have to finish what you have started"

#11030 - mandarin - Tue Sep 23, 2003 9:24 pm

I'm not sure whats wrong but this might help try it out

its a function I wrote,you can just customize it a bit to your needs let me know if it works.

Code:
int spritedisplay(int x, int y, int size, int no, int priority,int attrnum,int onoff)

{
   u16 loop;
   

   if(onoff == 0)
{
   initsprites();
}
   if(onoff==1)
{

   callsprites();
   
   if(size == 3232)
{
   sprites[no].attribute0 = COLOR_256 | SQUARE | x;
   sprites[no].attribute1 = SIZE_32 | y;
   sprites[no].attribute2 = attrnum | PRIORITY(priority);

   if(no==0)
   {
      for(loop = 0; loop < 512; loop++)
         OAMData[loop] = characterData[loop];
   }
   if(no>0)
   {
      for(loop = no*512; loop < no*512+512; loop++)
         OAMData[loop] = characterData[loop];
   }
}


   if(size == 1632)
{
   sprites[no].attribute0 = COLOR_256 | WIDE | x;
   sprites[no].attribute1 = SIZE_32 | y;
   sprites[no].attribute2 = attrnum | PRIORITY(priority);

   if(no==0)
   {
      for(loop = 0; loop < 256; loop++)
         OAMData[loop] = characterData[loop];
   }
   if(no>0)
   {
      for(loop = no*256; loop < no*256+256; loop++)
         OAMData[loop] = characterData[loop];
   }
   }
}

#11031 - mandarin - Tue Sep 23, 2003 9:31 pm

Code:
void initsprites()

{
   u16 loop;

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

#11032 - mandarin - Tue Sep 23, 2003 9:33 pm

Code:
void callsprites()
{
   u16 loop;
   
   for(loop = 0; loop < 256;loop++)
      OBJPaletteMem[loop] = spritePalette[loop];

   initsprites();
}

#11038 - yaustar - Wed Sep 24, 2003 12:43 am

Are you using the right dimensions for the wide sprites? I think they have set sizes for how wide is wide etc.
_________________
[Blog] [Portfolio]