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 > Sprites

#5509 - Wildginger - Wed Apr 30, 2003 11:10 am

Hi all,

Im a complete newbie, and am trying to get sprites to roll in from one side of the screen to the other to form a word.

I was successful in the first 4 letters/sprites, but then nothing happened. Its as if I cant access sprites 4 onwards in my sprites array. They are 256 colour, 64x64 sprites.

How many 64x64 sprites can I store and display on the screen at one time?

Sorry, dont have the code available at the moment.

Thanks in advance.
_________________
---
Wildginger (aka JimTownsend)

#5514 - Touchstone - Wed Apr 30, 2003 1:18 pm

The gba most often has 32kb of sprite ram (depending on video mode). That means 8 sprites with 4096 (64*64*1) bytes each. My favorite unofficial GBA hardware referense is at http://www.work.de/nocash/gbatek.htm, use it in good health.
_________________
You can't beat our meat

#5519 - niltsair - Wed Apr 30, 2003 2:06 pm

Yes but as a sprite goes offscreen, you can reload new data in it and re-use it to display new text,

There's 128 useable sprites on the Gba.

But those sprites object share a common 1024 tiles (in 16 color) or 512 tiles(in 256 colors) that they must use between themselves. Each tile is 8x8pixels.

And if you're using mode 3,4,5, don't forget that the tiles below 512(in 16colors) and 256(in 256colors) are nto useable.

#5526 - Wildginger - Wed Apr 30, 2003 7:57 pm

Hello again,

Thanks for the info, much appreciated.

So if I can have 8 times 64x64 256 colour sprites on a screen, I should be able to get p, a, c, m, a, n on the screen without too much trouble right?

Heres my code, would someone mind telling me where it is Ive gone wrong? It might be my maths, but I thought it looked ok. If its obvious and stupid, well blame it on the fact Im a complete novice!

Cheers,

Jim.


========= My dodgy beginners code ==========

//----------------//
// PAC LETTER 'P' //
//----------------//
//this is where we define our sprite atributes for the first sprite
//256 color 64x64 sprite that starts at character 0. Character 0 is
//the first sprite data memory location.

sprites[0].attribute0 = COLOR_256 | SQUARE| y;
sprites[0].attribute1 = SIZE_64 | x;
sprites[0].attribute2 = char_number + 512;

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index] = PData[index];
}
WaitForVsync();
// waits for the screen to stop drawing
CopyOAM();
// Copies our sprite array into OAM.

// now move the P across the screen
for( i = 0; i < 176; i++ )
{
x--;
MoveSprite( &sprites[0], x, y );
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
}


//----------------//
// PAC LETTER 'A' //
//----------------//

sprites[1].attribute0 = COLOR_256 | SQUARE| y;
sprites[1].attribute1 = SIZE_64 | x;
sprites[1].attribute2 = (char_number + 512) + 128;
x = 176;
y = 100;

iOffset = (256 * 8 ); // this is the offset for the second sprite in the array

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index + iOffset] = AData[index];
}
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
// Copies our sprite array into OAM.

// now move the A across the screen
for( i = 0; i < 144; i++ )
{
x--;
MoveSprite( &sprites[1], x, y );
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
}


//----------------//
// PAC LETTER 'C' //
//----------------//
sprites[2].attribute0 = COLOR_256 | SQUARE| y;
sprites[2].attribute1 = SIZE_64 | x;
sprites[2].attribute2 = (char_number + 512) + 256;

x = 176;
y = 100;

iOffset = (256 * 16 ); // this is the offset for the second sprite in the array

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index + iOffset] = CData[index];
}
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
// Copies our sprite array into OAM.

// now move the C across the screen
for( i = 0; i < 112; i++ )
{
x--;
MoveSprite( &sprites[2], x, y );
WaitForVsync();
// waits for the screen to stop drawing
CopyOAM();
}


//----------------//
// PAC LETTER 'M' //
//----------------//
sprites[3].attribute0 = COLOR_256 | SQUARE| y;
sprites[3].attribute1 = SIZE_64 | x;
sprites[3].attribute2 = (char_number + 512) + 384;

x = 176;
y = 100;

iOffset = (256 * 24 );

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index + iOffset] = mData[index];
}

WaitForVsync();

// waits for the screen to stop drawing

CopyOAM();
// Copies our sprite array into OAM.

// now move the M across the screen
for( i = 0; i < 80; i++ )
{
x--;
MoveSprite( &sprites[3], x, y );
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
}


//----------------//
// PAC LETTER 'A' //
//----------------//
sprites[4].attribute0 = COLOR_256 | SQUARE| y;
sprites[4].attribute1 = SIZE_64 | x;
sprites[4].attribute2 = (char_number + 512) + 512;

x = 176;
y = 100;

iOffset = (256 * 32 );

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index + iOffset] = A2Data[index];
}

WaitForVsync();
// waits for the screen to stop drawing
CopyOAM();
// Copies our sprite array into OAM.

// now move the A across the screen
for( i = 0; i < 48; i++ )
{
x--;
MoveSprite( &sprites[4], x, y );
WaitForVsync();

// waits for the screen to stop drawing
CopyOAM();
}


//----------------//
// PAC LETTER 'N' //
//----------------//
sprites[5].attribute0 = COLOR_256 | SQUARE| y;
sprites[5].attribute1 = SIZE_64 | x;
sprites[5].attribute2 = (char_number + 512) + 640;

x = 176;
y = 100;

iOffset = (256 * 40 ); // this is the offset for the second sprite in the array

// copy in the sprites bitmap
for(index = 0; index < 256*8; index++)
{
OAMData[index + iOffset] = nData[index];
}

WaitForVsync();
// waits for the screen to stop drawing
CopyOAM();
// Copies our sprite array into OAM.

// now move the N across the screen
for( i = 0; i < 16; i++ )
{
x--;
MoveSprite( &sprites[5], x, y );
WaitForVsync();
// waits for the screen to stop drawing
CopyOAM();
}

#5528 - niltsair - Wed Apr 30, 2003 8:13 pm

Which display mode are you using? One of those (3, 4, 5) or those (0,1,2)

If the anwser is (3,4,5) then i'm affraid you can only display 4 256colors 64x64 sprites at a time. And it seems to be the case because of the '512' in :
sprites[1].attribute2 = (char_number + 512) + 128; Which basicly skip the first 512 tiles because they're not usable in those mode. And this also means you lose the use of half the tiles, thus reducing your 8 sprites to 4.

So, you could either change your sprite to 16colors mode or (which will be easier if only displaying sprites and no background) use Display mode 0 and remove the +512


Last edited by niltsair on Wed Apr 30, 2003 9:33 pm; edited 1 time in total

#5530 - Wildginger - Wed Apr 30, 2003 9:27 pm

That makes perfect sense, thanks very much for the reply.

Yes, I am using mode 4, and I am displaying a background, so I shall make my sprites 16 colours.

Stand by for the "Why cant I display my 16 colour sprites properly" question ;)

Thanks again,

Jim
_________________
---
Wildginger (aka JimTownsend)

#5536 - Wildginger - Wed Apr 30, 2003 11:13 pm

OK, one more question, Ive been using pcx2sprite to convert my images, but it only takes 256 colour images.

I need a tool to convert 16 colour images to data, any ideas / preferences?

Cheers,
_________________
---
Wildginger (aka JimTownsend)