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.

C/C++ > sprites

#4144 - phr0zn - Thu Mar 20, 2003 8:36 pm

I am having trouble loading a third sprite in my Pong Demo. I load the first two sprites perfectly, but the thrid sprite loads as the top half of the "paddle" sprite. The paddle is 16x32, and the ball is 16x16. What is happening is the ball is loading as the first 16x16 of the paddle sprite (both located in the same header file). I believe the issue lies in the last loop of my code, but I cannot figure out what is going wrong. Thanks.

Also, for future reference, how do I load more sprites than 2 or 3? Is there some easy way to figure out the palette memory loop? I was able to figure out that for 16x32 it is 0->256, and 16x16 is 0->128 in the loop, but how do I load more than that?

Thanks.

Code:

void SetupSprites()
{
   u16 loop;

   for(loop = 0; loop < 256; loop++)          //load the palette into memory
      OBJPaletteMem[loop] = palette[loop];

   InitializeSprites();                       //set all sprites off screen (stops artifact)

    sprites[0].attribute0 = COLOR_256 | BIT15 | player.y_pos;   //setup sprite info, 256 colour, shape and y-coord
    sprites[0].attribute1 = BIT15 | player.x_pos;            //size 16x16 and x-coord
    sprites[0].attribute2 = 0;                      //pointer to tile where sprite starts

    for(loop = 0; loop < 256; loop++)               //load sprite image data
    {
        OAMData[loop] = paddleData[loop];
    }

   sprites[1].attribute0 = COLOR_256 | BIT15 | computer.y_pos;   //setup sprite info, 256 colour, shape and y-coord
    sprites[1].attribute1 = BIT15 | computer.x_pos;            //size 16x16 and x-coord
    sprites[1].attribute2 = 0; 


   sprites[2].attribute0 = COLOR_256 | SQUARE | pongball.y_pos;   //setup sprite info, 256 colour, shape and y-coord
    sprites[2].attribute1 = SIZE_16 | pongball.x_pos;            //size 16x16 and x-coord
    sprites[2].attribute2 = 8; 

   for(loop = 256; loop < 384; loop++)               //load sprite image data
    {
        OAMData[loop] = pongballData[loop-128];
    }

}
[/code]
_________________
http://cerberus.promodtecnologies.com

#4146 - darkcloud - Thu Mar 20, 2003 10:32 pm

I think you need to set attribute2 of sprite 2 to 16 rather than 8. I might be wrong though because sometimes I get confused about attribute 2. But it sounds like the answer, because if attribute2 is not set correctly, your sprite can turn out the way it did, (half of one sprite, half of another).

To load in a sprite larger than 16x16, (I think you want to know how to calculate the number of times you need to loop),you just multiply the dimensions and divide by 2, for 256-color sprites.
Ex)
16x32 --> 16 X 32 --> 512
512 / 2 = 256

64x64 --> 64 X 64 --> 4096
4096 / 2 = 2048
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.

#4150 - phr0zn - Thu Mar 20, 2003 11:41 pm

as for the attribute2, is it safe to assume that for every '128' in the loop, to add 8? so the first sprite will be 0-16, and the second sprite (at 256-384) will be 16-24. The thrid sprite, assuming it is another 128 in the palette will be 24-32? Or if it was 256 in the sprite, 16-32?

I will try that.

Thanks.
_________________
http://cerberus.promodtecnologies.com