How to duplicate sprites using VRAM tiles once?
Moderator: Stef
How to duplicate sprites using VRAM tiles once?
Let me explain, using some images:
Currently, we are searching for a way to create composed animated sprites,
where the second, third and fourth sprite use the graphical
data from the first sprite, using the same VRAM tiles, but
horizontally mirrored, vertically mirrored and hor. and vert. mirrored.
In order to save precious VRAM and reduce needed bandwidth
(currently there are many animated sprites at once,
while many of the explosion effects can be reduced
to a single quarter, in terms of number of tiles and DMA bandwidth).
The result we are searching is this:
As you can see, your huge explosion,
can be decomposed into 4 parts,
being actually the first sprite the unique
that updates its tiles through the DMA.
Currently, we are searching for a way to create composed animated sprites,
where the second, third and fourth sprite use the graphical
data from the first sprite, using the same VRAM tiles, but
horizontally mirrored, vertically mirrored and hor. and vert. mirrored.
In order to save precious VRAM and reduce needed bandwidth
(currently there are many animated sprites at once,
while many of the explosion effects can be reduced
to a single quarter, in terms of number of tiles and DMA bandwidth).
The result we are searching is this:
As you can see, your huge explosion,
can be decomposed into 4 parts,
being actually the first sprite the unique
that updates its tiles through the DMA.
Last edited by masteries on Sun Oct 09, 2022 11:56 am, edited 1 time in total.
Re: How to generate Horizontal & Vertical mirrored based sprites from a "father" sprite?
The question can be simplified as:
How to share the graphical data for a set of sprites?
Where only one of the sprites update its tiles, and other ones only perform some flag changes, such H mirror and so on.
How to share the graphical data for a set of sprites?
Where only one of the sprites update its tiles, and other ones only perform some flag changes, such H mirror and so on.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: How to duplicate sprites using VRAM tiles once?
You can do that by using so you define where the sprite tiles are located in VRAM.
You have this function function which load all frames of a SpriteDefinition so you can easily share the tile indexes along several sprites then. The sonic sample show an usage example of SPR_loadAllFrames(..)
For your explosion i think the simplest is just to cut your big sprite in 4 small sprites and use with some offsets on position to build up your final sprite.
Code: Select all
SPR_setVRAMTileIndex(..)
You have this function
Code: Select all
SPR_loadAllFrames(..)
For your explosion i think the simplest is just to cut your big sprite in 4 small sprites and use
Code: Select all
SPR_setHFlip(..) / SPR_setVFlip(..)
Re: How to duplicate sprites using VRAM tiles once?
Stef wrote: ↑Mon Oct 10, 2022 9:16 amYou can do that by usingso you define where the sprite tiles are located in VRAM.Code: Select all
SPR_setVRAMTileIndex(..)
You have this functionfunction which load all frames of a SpriteDefinition so you can easily share the tile indexes along several sprites then. The sonic sample show an usage example of SPR_loadAllFrames(..)Code: Select all
SPR_loadAllFrames(..)
For your explosion i think the simplest is just to cut your big sprite in 4 small sprites and usewith some offsets on position to build up your final sprite.Code: Select all
SPR_setHFlip(..) / SPR_setVFlip(..)
Code: Select all
SPR_loadAllFrames(..)
There is a 1000 tiles framebuffer in VRAM (some screens have more than 900 different tiles at once),
and around 700 free tiles for 20+ sprites...
If I execute this sentence:
Code: Select all
SPR_setVRAMTileIndex(entidad[aux].spr)
without this one:
Code: Select all
SPR_setAutoTileUpload(entidad[aux].spr, FALSE);
and without sharing the sprite data structure,
will the new duplicated sprites do not try to upload their tiles?
And yes, for the explosions, the idea is to spawn a single sprite that updates the animation frames (change the tiles);
and the other sprites of the composition using H-Flip and V-Flip.
I will test and report asap,
Thanks!
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: How to duplicate sprites using VRAM tiles once?
If you can't preload all animation frame then yeah, what you need is to have kind of "master" sprite which handle the tile upload. You can use a dummy out of screen sprite with forced visibility (otherwise tile upload won't happen) to handle that, so you don't have to worry about which current visible sprite is the master one. Then all other sprites sharing the same current animation frame should be set in SPR_setAutoTileUpload(FALSE).masteries wrote: ↑Mon Oct 10, 2022 3:33 pmThis couldn´t be used due to severe memory restrictions;Code: Select all
SPR_loadAllFrames(..)
There is a 1000 tiles framebuffer in VRAM (some screens have more than 900 different tiles at once),
and around 700 free tiles for 20+ sprites...
If I execute this sentence:
Code: Select all
SPR_setVRAMTileIndex(entidad[aux].spr)
without this one:
and without sharing the sprite data structure,Code: Select all
SPR_setAutoTileUpload(entidad[aux].spr, FALSE);
will the new duplicated sprites do not try to upload their tiles?
You can then use the SPR_setFrameChangeCallback(..) to handle special action when your master sprite change its current animation frame:
Code: Select all
SPR_setFrameChangeCallback(masterSprite, masterSpriteChanged);
...
void masterSpriteChanged(Sprite* master)
{
u16 animInd = maser->animInd;
u16 frameInd = maser->frameInd;
u16 tileIndex = maser->attribut & TILE_INDEX_MASK;
for(u16 i = 0; i < numSlave; i++)
{
Sprite* slave = slaveSprites[i];
// set animation and frame
SPR_setAnimAndFrame(slave, animInd, frameInd);
// set tile index
SPR_setVRAMTileIndex(slave, tileIndex);
}
}
Hope that make sense for you.
Re: How to duplicate sprites using VRAM tiles once?
Thanks for the code sample, now it is clear!
This solution will be applied for debris and explosions.
This solution will be applied for debris and explosions.