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 > display 2 sprites

#174745 - stra?enschild - Tue Jul 13, 2010 8:12 pm

hey guys,
i ran into some problems trying to display 2 sprites on the screen.
here are my sprites functions:

Code:
oamInit(&oamMain, SpriteMapping_Bmp_1D_256, false);
oamEnable(&oamMain);
u16* gfx = oamAllocateGfx(&oamMain, SpriteSize_32x32,SpriteColorFormat_256Color);

dmaCopyHalfWords(3,fireTiles,gfx, fireTilesLen);
dmaCopyHalfWords(3,firePal, SPRITE_PALETTE, firePalLen);

dmaCopyHalfWords(3,spriteTiles,gfx, spriteTilesLen);
dmaCopyHalfWords(3,spritePal, SPRITE_PALETTE, spritePalLen);

oamSet(&oamMain,0,positionx,positiony,1,0,SpriteSize_32x32,SpriteColorFormat_256Color,gfx,0,true,false,false,false,false);

oamSet(&oamMain,1, 20, 20,0,0,SpriteSize_8x8,SpriteColorFormat_256Color,gfx,0,true,false,false,false,false);

with the code above i only get sprite called sprite displayed.
The sprites are .png files and were generated with grit.

#174746 - vuurrobin - Tue Jul 13, 2010 9:15 pm

you are only allocating memory for 1 sprite, so the gfx of your second sprite is overwriting the gfx of your first sprite. same with the palette.
_________________
my blog:
http://vuurrobin.100webcustomers.com/

#174750 - stra?enschild - Wed Jul 14, 2010 7:56 pm

thanks for your reply, could you please post how i have to modify my code.
I have just started to code for the ds, so all is new and confusing to me.
sorry for beeing such a newbie ;)

#174751 - headspin - Thu Jul 15, 2010 12:19 am

Allocate RAM for each sprite and then use the appropriate pointer.

Code:
oamInit(&oamMain, SpriteMapping_Bmp_1D_256, false);
oamEnable(&oamMain);

u16* gfx1 = oamAllocateGfx(&oamMain, SpriteSize_32x32,SpriteColorFormat_256Color);
u16* gfx2 = oamAllocateGfx(&oamMain, SpriteSize_8x8,SpriteColorFormat_256Color);

dmaCopyHalfWords(3,fireTiles,gfx1, fireTilesLen);
dmaCopyHalfWords(3,firePal, SPRITE_PALETTE, firePalLen);

dmaCopyHalfWords(3,spriteTiles,gfx2, spriteTilesLen);
// I assume your palettes are the same in which case this is not needed
dmaCopyHalfWords(3,spritePal, SPRITE_PALETTE, spritePalLen);

oamSet(&oamMain,0,positionx,positiony,1,0,SpriteSize_32x32,SpriteColorFormat_256Color,gfx1,0,true,false,false,false,false);
oamSet(&oamMain,1, 20, 20,0,0,SpriteSize_8x8,SpriteColorFormat_256Color,gfx2,0,true,false,false,false,false);

_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game