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 > Problem with sprite in mode 0

#64894 - naleksiev - Wed Dec 28, 2005 4:58 am

Hello,
This is my first steps in GBA. I'm playing with sprites in mode 0. I have some problems with my test this is what I see http://alex.logiga.com/error.png in the left top corrner there is some garbage. My sprite is a rectangle with rounded angles. For some reason I can see only the upper half and this garbage. Any ideas?

This is how I initialize mode 0
Code:
REG_BG0CNT = BIT2 | BIT7;
SetMode(MODE_0 | BG0_ENABLE | OBJ_ENABLE);

This is the code that initialize the position of my sprite
Code:
   sprites[id].oam = &OAMCopy[id];
   sprites[id].x = x;
   sprites[id].y = y;
   sprites[id].gfxID = 0;

   sprites[id].oam->attribute[0] = COLOR_256 | SQUARE | (y & 0x00FF); 
   sprites[id].oam->attribute[1] = SIZE_16 | (x & 0x01FF);
   sprites[id].oam->attribute[2] = sprites[id].gfxID;

   for (int i = 0; i < spriteRawLength >> 1; i++) {
      OBJ_GFXMem[sprites[id].gfxID * 16 + i] = spriteRaw[i]; 
   }

   for (int i = 0; i < spritePalLength >> 1; i++) {
      OBJPaletteMem[i] = spritePal[i];
   }

where id = 0


What is the problem? Please help.

#64895 - gauauu - Wed Dec 28, 2005 5:35 am

The junk in the upper-left is probably all the other sprites that you didn't hide. If you didn't specifically hide them, they will all tend to appear up there with whatever was in that memory (random garbage)

The reason the rest of the sprite isn't showing up possibly has to do with 1d vs 2d mapping. The default is 2d, so open up vba's tile viewer, and make sure your sprite didn't get exported in 1d mode. How can you tell?

If it's in 1d mode, all the tiles for that sprite will be in a row. If in 2d, they will (depending on your version of vba) probably have the top half in one place, and the bottom half on the same line, further off to the right.

edit: this applies to 256 color sprites which you are using. if you use 16 color sprites, they will be spaced out to look just like your sprite should look.

For example:

Your sprite (each number is a tile):
12
34

In 1d mode, it will be like: 1234
In 2d (256 color) mode, it will be like: 12xxxxxxxxxxxxxx34xxxxxxxxxxxxxxxx
(where x is some other tile)

In 2d (16 color), it will be like:
12xxxxxxxxxxxxxxxxxxxxx
34xxxxxxxxxxxxxxxxxxxxx

If it's exported as 1d, you can either change the mapping method in the display controller (something like REG_DISPCNT |= DCNT_OBJ_1D), or change your graphic exporter tool to spit it out in 2d mode.

#64896 - naleksiev - Wed Dec 28, 2005 6:55 am

Thanks for your answer.

You ware right about 1D/2D. Now my sprite is complete. But the issue with garbage in the corner still occure.

Yhis is the code that I execute before start loading my sprites.
Code:
   for (int i = 0; i < 128; i++) {
      OAMCopy[i].attribute[0] = SPRITE_OFF; 
   }


Thanks again

#64897 - naleksiev - Wed Dec 28, 2005 7:17 am

Sorry for previews question I've just found my mistake. In UpdateOAM I updated only first sprite. Now my code is
Code:
   for (u32 i = 0; i < 128 * sizeof(OAMEntry) / 4; i++) {
      ((u32*)OAMMem)[i] = ((u32*)OAMCopy)[i];
   }

and everyting is great.
Thanks for your fast answer.