frameChanged() and sprTileIndexes [] questions?

SGDK only sub forum

Moderator: Stef

Post Reply
DavilaGames
Interested
Posts: 10
Joined: Thu Jul 04, 2019 4:25 am
Location: Juiz de Fora/MG, Brasil
Contact:

frameChanged() and sprTileIndexes [] questions?

Post by DavilaGames » Tue Dec 29, 2020 1:21 pm

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?
Yuri d´Ávila
DAVILA GAMES
https://www.davilagames.com.br

DavilaGames
Interested
Posts: 10
Joined: Thu Jul 04, 2019 4:25 am
Location: Juiz de Fora/MG, Brasil
Contact:

Re: frameChanged() and sprTileIndexes [] questions?

Post by DavilaGames » Thu Jul 22, 2021 5:14 pm

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.
Yuri d´Ávila
DAVILA GAMES
https://www.davilagames.com.br

Stef
Very interested
Posts: 3088
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: frameChanged() and sprTileIndexes [] questions?

Post by Stef » Fri Jul 23, 2021 7:53 am

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."

DavilaGames
Interested
Posts: 10
Joined: Thu Jul 04, 2019 4:25 am
Location: Juiz de Fora/MG, Brasil
Contact:

Re: frameChanged() and sprTileIndexes [] questions?

Post by DavilaGames » Thu Jul 29, 2021 2:45 am

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:
Yuri d´Ávila
DAVILA GAMES
https://www.davilagames.com.br

Stef
Very interested
Posts: 3088
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: frameChanged() and sprTileIndexes [] questions?

Post by Stef » Fri Jul 30, 2021 7:13 am

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.

Post Reply