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 > tile mode 0, sprite not displaying properly

#20390 - tethered - Mon May 10, 2004 5:59 am

hello,

i've got a solid understanding of tile mode 0 and the text backgrounds and have decided to move on to sprites. i'm able to get a sprite to display on the screen but it doesn't appear as expected. i was hoping someone here could clarify why.

here's the source:

Code:
#include "includes\gba.h"
#include "graphics\sprites.pal.c"
#include "graphics\ship.raw.c"


OAMEntry sprites[128];


int main(void)
{
    u16 i;
    u16* temp;
    s16 x = 104, y = 64; // center of screen
   
    SetMode(MODE_0 | OBJ_ENABLE | OBJ_MAP_1D);
   
    // clear any sprite data from the screen
    for (i = 0; i < 128; i++)
    {
        sprites[i].attribute0 = 160;
        sprites[i].attribute1 = 240;
        sprites[i].attribute2 = 0;
    }
   
    // set sprite oam data
    sprites[0].attribute0 = COLOR_256 | SQUARE | y;
    sprites[0].attribute1 = SIZE_32 | x;
    sprites[0].attribute2 = 0;
   
    // load palette
    for (i = 0; i < 256; i++)
        OBJ_PaletteMem[i] = sprite_Palette[i];
       
    // load sprite data
    for (i = 0; i < 512; i++)
        OBJ_Data[i] = ((u16*)ship_Tiles)[i];
       
    // game loop
    while(1)
    {
        vsync();
       
        // load oam data
        temp = (u16*)sprites;
        for (i = 0; i < 512; i++)
            OAM_Mem[i] = temp[i];
    }
   
    return 0;
}


here's the array definition for the sprite:

Code:
const unsigned char ship_Tiles[1024] = {
. . .
}


any ideas?

thanks,


chuck

#20391 - tepples - Mon May 10, 2004 6:05 am

In general, we need more than "doesn't appear as expected" to help you. Do you have a screenshot or a more detailed description?

Have you made sure to align ship_Tiles[] to a 16-bit boundary? It appears not.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#20392 - tethered - Mon May 10, 2004 6:11 am

screenshot:

[Images not permitted - Click here to view it]

and i'm not sure what you mean when you ask if i've aligned it to a 16 bit boundary. as you can see by the declaration, its an unsigned char, so each pixel is 8 bits...

#20394 - tepples - Mon May 10, 2004 6:15 am

Looks like a data conversion error. You seem to have converted your bitmap in linear mode, whereas sprite cels require tile mode. Which graphics conversion program did you use, with which command line?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#20395 - tethered - Mon May 10, 2004 6:18 am

i'm using gfx2gba, and the command was gfx2gba -fsrc -t8 *.bmp ... i noticed some tiles were dropped during the conversion and i made a mental note of it but with all the other things i'm grappling w/ it escaped me...

should i convert it again w/o the -t8 switch?

[edit: same result w/o the -t8 switch]

#20396 - sajiimori - Mon May 10, 2004 8:09 am

Try using a simple image, like a circle or a checkerboard, then convert that and visually inspect the emitted source code to see if it's what you expected.