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.

Coding > Sprites in MODE 3

#43916 - qbert - Sat May 28, 2005 1:18 am

I have 2 very small sprites to use in my program, converted to a data and palette array each. I can use one or the other, but I'm having trouble using both sprites at the same time.

I'm new to gba and c - let me know if this question is too vague.
thanks.

#43917 - tepples - Sat May 28, 2005 2:24 am

Do they both show up in VisualBoyAdvance's tile viewer under the 0x06010000 section?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43949 - qbert - Sat May 28, 2005 4:21 pm

I see some colors but no clear image in VisualBoyAdvance's tile viewer.

The book I'm using some code from only displays 1 sprite in the examples.
Each sprite works fine alone, but I can't display both at the same time. Below is some of the code.

int main()
{
int n;
int i;
int x;

// Set video mode
SetMode(3 | OBJ_ENABLE | OBJ_MAP_1D | BG2_ENABLE);

// Draw the board
for(n = 0; n < 38400; n++)
videoBuffer[n] = bg_Bitmap[n];

// set sprite palette
for(n=0; n < 256; n++)
SpritePal[n] = blackstonePalette[n];

for(n=0; n < 512; n++)
SpriteData3[n] = blackstoneData[n];

// move sprite off screen
HideSprites();

x = 0;
n = 0;

i = 1;
InitSprite(i, horizontalPlacement[x], verticalPlacement[n], blackstone_WIDTH, COLOR_256, 512);
WaitVBlank();
MoveSprite(n);
UpdateSpriteMemory();


Everything works fine to here.
The board background is drawn and 1 black game piece

After this point, I want to keep the board and black game piece, but also add a white game piece at another spot. The code below does add the game piece but changes both to white.



// set sprite palette
// for(n=0; n < 256; n++)
// SpritePal[n] = whitestonePalette[n];

// for(n=0; n < 512; n++)
// SpriteData3[n] = whitestoneData[n];

i = 2;
x = 18;
n = 18;
InitSprite(i, horizontalPlacement[x], verticalPlacement[n], blackstone_WIDTH, COLOR_256, 512);
WaitVBlank();
MoveSprite(n);
UpdateSpriteMemory();


}

/* END OF FILE */

#44019 - Issac - Sun May 29, 2005 1:11 pm

I dont know, but isn't it because you overwrite the black piece pallette with the white ones.... :S (or the data?)
I am not sure, but thats my guess...
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#44022 - qbert - Sun May 29, 2005 1:59 pm

Yes - that's what's happening. I'm not sure how to use both palettes at the same time. This pgm is pretty much a 'monkey job' - i pasted and modified code samples. So I'm not real solid on what's happening.

#44023 - Issac - Sun May 29, 2005 2:12 pm

Code:
 // set sprite palette
for(n=0; n < 256; n++)
SpritePal[n] = blackstonePalette[n];

for(n=0; n < 512; n++)
SpriteData3[n] = blackstoneData[n];


here you load the black one into the Palette.
I guess you've defined "SpritePal" and "SpriteData3" somewhere in the code..
Because you load the White one OVER the black (changing the black to white too) here:
Code:
 // set sprite palette
// for(n=0; n < 256; n++)
// SpritePal[n] = whitestonePalette[n];

// for(n=0; n < 512; n++)
// SpriteData3[n] = whitestoneData[n];


So my guess would be that you have to define a few more things. like:
SpriteData4 and SpritePal2 for example, and use the correct memory usage and all (can be quite hard to do).

I guess someone better than me should help you with that part :)
_________________
yeah, well, maybe... or? anyways.... eh... what was i talking about??

#47429 - blacksun - Fri Jul 08, 2005 7:33 pm

Well first thing if your images are 256 color you can only use one palette. So you just have to store one palette and copy that.

Second, you need to index into your SpriteData3 array for your second sprite. What you are doing is overriding the data for your sprite with the white one. So for instance you would start the second sprite at SpriteData3[512] since that is the end of your first sprite. But you also have to make sure when you are indexing your white data that you start from 0 and not 512.

Also, what is the size of your sprites and how many frames of animation? Because if its a small sprite (8x8) and only one frame you should only have a size of (8x8 / 2) which is 32.