Page 1 of 1

frameChanged() and sprTileIndexes [] questions?

Posted: Tue Dec 29, 2020 1:21 pm
by DavilaGames
Hello.
I have a question about the "sprite" (Sonic) sample that comes in SGDK.
in relation to frameChanged () and sprTileIndexes []. They load the enemy's sprites into VRAM, but when I create a wave of new enemies with

Code: Select all

e-> sprite = SPR_addSprite (& spr_enemy01, posX, posY, TILE_ATTR (PAL2, FALSE, FALSE, FALSE));
they appear again in the VRAM part, in the part dedicated to sprites. How do I load the sprites that were previously loaded in VRAM instead of adding them back to VRAM?

Re: frameChanged() and sprTileIndexes [] questions?

Posted: Thu Jul 22, 2021 5:14 pm
by DavilaGames
Now I can choose which VRAM address I will add my Sprite to, with SPR_setVRAMTileIndex(); but I would like to do otherwise. I would like to add on the screen, an Sprite that comes from that specific address.

Re: frameChanged() and sprTileIndexes [] questions?

Posted: Fri Jul 23, 2021 7:53 am
by Stef
Hey :)

As you can see in the Sonic sample, enemies sprite sheet is preloaded in VRAM and indexes are stored in an array, then when frame changed i just set the VRAM index for the sprite to the desired VRAM index. I'm not sure to understand exactly what you mean by "I would like to do otherwise. I would like to add on the screen, an Sprite that comes from that specific address."

Re: frameChanged() and sprTileIndexes [] questions?

Posted: Thu Jul 29, 2021 2:45 am
by DavilaGames
Now, I understood the correct behavior of what I wanted to do. Just like in Sonic's Sample, I would add a sprite to the canvas with SPR_addSprite() and store its index in sprTileIndexes[], but when I wanted to add the same sprite again using SPR_addSprite(), the new one took up another space in the VRAM. I actually have to use the SPR_setVRAMTileIndex() pointing to the same previous index, which I didn't do. I figured I would have to use something like SPR_addSpriteFromVRAM(sprite, ind) or SPR_getSpriteFromVRAM(sprite, ind), something like that. Thank you, now I understood what to do! :idea:

Re: frameChanged() and sprTileIndexes [] questions?

Posted: Fri Jul 30, 2021 7:13 am
by Stef
Oh ok, in fact you have the SPR_addSpriteEx(..) which let you to define more parameter, and set the fixed VRAM index for instance, but if you call SPR_setVRAMTileIndex(..) afterward it works too.