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 > oam memory managment / multiple sprites with one picture?

#152565 - ben0bi - Mon Mar 17, 2008 8:50 pm

is there a simple way to manage the oam memory?

i have the following problem: i want to make much much units. everyone has eventually another sprite.

to show the right units on the screen, i have to determine the visible ones and then copy their sprites and position/rotation data to oam. (and flush away the invisible ones to get the memory)

or can i load ONE sprite to oam and use it for several instances? (how?)

now please look at the following code:

Code:

      /* Copy over the sprite palette */
      dmaCopyHalfWords(OAM_SPRITE_DMA_CHANNEL,
                     ppicturePal,
                     &SPRITE_PALETTE[sprInfo->oamId *
                                     OAM_COLORS_PER_PALETTE],
                     picturePalLEN);

      /* Copy the sprite graphics to sprite graphics memory */
       dmaCopyHalfWords(OAM_SPRITE_DMA_CHANNEL,
                     ppictureTiles,
                     &SPRITE_GFX[sprEntry->tileIdx * OAM_MAINSPR_OFFSET_MULTIPLIER],
                     pictureTilesLEN);


by simply changing the oam id (sprInfo->oamID) everything works until several sprites are loaded (because palette len is ever the same). then the tileIdx will overrun because it is calculated somewhat like this:

sprEntry->tileIdx= actualTileIdx;
actualTileIdx+=mypicBitmapLen;

now, i cannot set actualTileIdx - = oldpicBitmapLen because on this position could be another sprite.

its no problem with the palette, but the new tileIdx would eventually overlap other sprites if i use the stuff above or the old tileIdx.

now my question: is there something provided to manage this issue?
(wich e.G. shifts all space behind the old position "left" with oldBitmapLen (so i can use actualTileIdx -= oldpicBitmapLen)

or is there another way to show one sprite image on multiple positions/angles at the same time?

#152584 - silent_code - Mon Mar 17, 2008 11:52 pm

you can have two sprites (on the same 2d engine / screen) mapped to the same graphics. just give them the same tile number. that way you can have 50 units, that look all the same, but you don't need 50 identical tilesets.
same goes for animations, just put them in the right place (sprite graphics memory) and assigne each sprite the according frame's tile number. all sprites can then be animated individually, but you just need memory for one animation.

hope that helps a bit.