Page 1 of 1
How to avoid redundant Sprite tiles in tile cache in VRAM?
Posted: Sat Mar 01, 2014 5:09 pm
by Manveru
Hi mates.
I am tasting SGDK 0.95 (congrats for the new great version) and i have a problem: i need to add a single enemy to the screen a lot of times, for example 10 times, so i have to create 10 Sprite vars and 10 spriteDefinition and 10 .png files with the rescomp, one for every enemy, and add everyone of them to the sprites engine having the same tileset 10 times in the tile cache in the VRAM... How can i avoid that and just add that tileset once per enemy type?
Thanks.
Posted: Sat Mar 01, 2014 6:22 pm
by Stef
Hi Manveru,
If i understand correctly you want to display 10 times the same sprites right ? So why are you using 10 SpriteDefinition ? Only 1 is enough :
Code: Select all
SpriteDefinition enemy;
Sprite sprites[10];
u16 i;
// set palette of enemy sprite in PAL0
VDP_setPalette(PAL0, enemy.palette->data);
// init 10 sprites with 'enemy' definition
for(i = 0; i < 10; i++)
SPR_initSprite(&sprites[i], &enemy, 20 + (i * 32), 40, TILE_ATTR(PAL0, FALSE, FALSE, FALSE));
// display my 10 sprites
SPR_update(sprites, 10);
This way all your sprites will use the same SpriteDefinition.
Posted: Sat Mar 01, 2014 9:59 pm
by Manveru
Hi Stef, thanks for your answer.
That's the thing i tried the first, but i got some random results. The sequence of animations did not work properly because i set the Sprite fields different values (diferent animation, frames and timer) and i got some strange behavior in the sprites. I have try now to redo this but with all the enemies with the same values and patern, and that way it works. Then i have begun to undo all the steps to make my code to give the enemies a different behavior since the initialization (as they have before when the issue), and now it works xD, sometimes i ask myself why am i a programmer...
I feel a bit stupid, i can“t understand what made my code buggy before if i have now the "same" code working... In any case i am happy that the problem was easily resolved. Thanks again Stef.
Posted: Sun Mar 02, 2014 9:50 am
by Stef
Actually the Sprite structure contains everything about the current patten and animation step etc... the SpriteDefinition only contains the frame resources itself. Still for the moment, when you use rescomp to generate your SpriteDefinition structures you will have restrictions as same frame size, same timing between each frame...
For the timing you can easily control it by using 0 by default and then handle it manually from the Sprite structure

And i know that really need some documentations !
Posted: Sun Mar 02, 2014 2:20 pm
by Manveru
It is a very good engine. Will be incredible when you can use frames with different sizes, but now with the Sprite structure you can control all the paterns, as you said, and it works great and it is easy to use. I just had that issue and i still don't know why it didn't work but, after that epic fail of mine, i can see it is a very good and intuitive system to control sprites, animations and frames.
The limitation of the fixed frame size could the fixed if you could modify the const var generated with rescomp. There is a way to modify a const var, but i do not know if doing that is a 'legal' and a harmful thing...
Posted: Sun Mar 02, 2014 2:49 pm
by Stef
Thanks for the comment about the sprite engine

Unfortunately it has some flaws and one of them is the performance. It regenerate the complete list of sprite each time and this is really slow :-/ I believe you cannot handle much sprites without experiencing slowdowns but for a simple game it should be enough !
Also the problem with modifying manually generated resources from rescomp is that it will erase all your changes as soon you modifying the base image.
A better method is to use custom tools or scripts to generate the different SpriteDefinition (in inner) structures exactly as we want. Later i eventually plan to design a tool to make sprites and animations in a much more flexible way but i believe that won't happen in a close future unfortunately :-/
Posted: Mon Mar 03, 2014 2:34 pm
by Manveru
Ok thanks Stef for your help