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 > How to handle more than 15 sprites (size 16x16, 16 col)?

#156472 - mca - Sat May 10, 2008 10:13 am

Hi,

I'm new to this forum and to DS development. I read Patater's great manual, in which he explains sprite handling in detail.

In my first project I need to display a maximum of 63 different sprites.
Each sprite is 16 color and 16x16 pixels in size.

I use
Code:
vramSetBankE(VRAM_E_MAIN_SPRITE);

for holding the sprite data (tiles,palette,...).

With each sprite displayed I assign a new SpriteBuffer in the OAM.
I calculate a new TileStartingAdress (address aligned to the standard 32 byte) and a new palette adress.

As long as I display fewer than 16 sprites all works fine.
Displaying any more than 15 sprites results in strange artifacts, corrupted tiledata and palette data. After placing 48 sprites it even comes to an error in the palette of the main background. I don't understand the things happening here.
Can someone shed light on this?
Is there any code example handlig with this amount of sprites?

Thanks in advance...
mca

#156474 - silent_code - Sat May 10, 2008 11:49 am

well, welcome to the scene! :^)

it depends on how you handle the sprites.
in general, you have only 256 colors for the palette.
using 16 color (4 bit) sprites, gives you 16 sub palettes, which can be assigned to any sprite.
if you write past the 256th color, you'll corrupt other memory.
check out gbatek to see how the memory areas are layed out!

gbatek wrote:
5000000h Engine A Standard BG Palette (512 bytes)
5000200h Engine A Standard OBJ Palette (512 bytes)
5000400h Engine B Standard BG Palette (512 bytes)
5000600h Engine B Standard OBJ Palette (512 bytes)
7000000h Engine A OAM (1024 bytes)
7000400h Engine B OAM (1024 bytes)


depending on your game's requirements, you can also reuse existing sprite tilesets (graphics) for different sprites, that look the same.

happy coding!

#156476 - mca - Sat May 10, 2008 12:22 pm

Thanks for clarifying.

While re-reading Pataters manual I saw, that I oversaw this info about sprites:

Quote:
...Another advantage of using 16-color sprites is the ability to use 16 different palettes. ...


....and not more. You pointed it out.
My first (errorous) thought for an easy approach was to give each sprite its own palette and own tiledata.

Because the 63 sprites are made of only 8 different shapes/palettes, I'll now go for
initializing the 8 sprites and map them on VRAM and then
let the OAM attributes for 63 sprites point to these areas.

Hope this will work.

Frohe Pfingsten...
mca

#156479 - silent_code - Sat May 10, 2008 2:02 pm

hahahaha!
frohe pfingsten! :^D
i'll keep writing in english, though. ;^)

you can also use the extended palette feature of the nds, in case you need to use more palette entries than are available in the standard oam palette.
yes, i just wrote "palette" three times in just one sentence! :^P