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.

DS development > Multiple Sprites

#120931 - peper - Wed Mar 07, 2007 11:15 am

Hi,

I'm having a small problem with my latest code and I really lack of knowledge here. The problem is quite simple:

Load two different *.pcx images and display them. Both images have a hight and width of 32px and share the same palette.

Code:

// load image a
sImage img_a;
loadPCX((u8*))a_pcx, &img_a);

// tile image a
imageTileData(&img_a);

// initialize the palette
for(int i = 0; i < 256; i++) SPRITE_PALETTE[i] = img_a.palette[i];

// load the image data
for(int i = 0; i < 512; i++) SPRITE_GFX[i] = img_a.image.data16[i];

/*
    up until this point everything is working fine
*/

// load the second image
sImage img_b;
loadPCX((u8*))a_pcx, &img_b);
imageTileData(&img_b);

/*
    now where to store the data of the second image?
*/


Now

Code:

for(int i = 0; i < 512; i++) SPRITE_GFX[i] = img_b.image.data16[i];

will overwrite the data of the first image but
Code:

for(int i = 512; i < 1024; i++) SPRITE_GFX[i] = img_b.image.data16[i];

won't work either. With the second code the emulator shows that the data from 512 until 1024 in SPRITE_GFX is the same as from 0 to 512. I do not assume that everytime I need to draw a sprite that I need to copy the image data into the SPRITE_GFX first. So I think the overall question is: How do I map the sprite data to the SpriteEntry?

I would appreciate every idea.

Regards,

#120932 - thehive - Wed Mar 07, 2007 11:35 am

Because you've just started i from 512, you've also offset where you're copying the data from.

I suppose you want something like this below;

Code:

for(int i = 0; i < 512; i++) SPRITE_GFX[i+512] = img_b.image.data16[i];

#120933 - peper - Wed Mar 07, 2007 11:47 am

thehive wrote:
Because you've just started i from 512, you've also offset where you're copying the data from.

I suppose you want something like this below;

Code:

for(int i = 0; i < 512; i++) SPRITE_GFX[i+512] = img_b.image.data16[i];


D'oh! Thank you very much.