Removing a sprite from screen

SGDK only sub forum

Moderator: Stef

Post Reply
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Removing a sprite from screen

Post by matteus » Thu Sep 17, 2015 1:10 pm

Hi,
I'm using the sprite engine, I use SPR_clear after a sprite has finished animating on screen. However I'm still seeing tiles left in VRAM?

Code: Select all

case 3:
	VDP_setPalette(PAL3, ghoul_sprite.palette->data);
	SPR_initSprite(&sprites[0], (SpriteDefinition*)&ghoul_sprite, EMEMYSPRITE_POSITION_X, ENEMYSPRITE_POSITION_Y, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
	SPR_setAnim(&sprites[0], ANIM_DEFEATED);
break;

// code lower down in next case statement
case 4:
if (AnimFrame < 7) {
        SPR_nextFrame(&sprites[0]);
        SPR_update(sprites, 1);
	AnimFrame++;
} else {
	SPR_clear();
	updateStatistics();
}


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

Re: Removing a sprite from screen

Post by Stef » Thu Sep 17, 2015 7:54 pm

SPR_clear() just clear sprites from display, tiles won't necessary be cleared from VRAM which rely from the internal VRAM cache logic part.
Why do you want to removes tiles from VRAM ?

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Removing a sprite from screen

Post by matteus » Thu Sep 17, 2015 9:35 pm

I wondered if this maybe causing the corruption? But I guess you overwrite anything left behind in VRAM that's no longer used! I'm starting to get a real understanding of how this all works :) Loving it too!

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

Re: Removing a sprite from screen

Post by Stef » Thu Sep 17, 2015 9:48 pm

Yeah exactly at some point i will overwrite it when it will not be anymore in use. But as i told you, unfortunately there is still some issues with the sprite engine i need to fix. Be sure to have a big enough cache to start with... but i know that sometime it's just because of slow update which make corruption to appears on screen. Do you use compressed sprites data ? if yes, try to disable it to see if it helps.

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Removing a sprite from screen

Post by matteus » Thu Sep 17, 2015 10:44 pm

I disabled compression earlier today and it fixed the issue and the frame rate went mad! Is there any way to calculate when a sprite has finished an animation loop?

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

Re: Removing a sprite from screen

Post by Stef » Fri Sep 18, 2015 8:05 am

matteus wrote:I disabled compression earlier today and it fixed the issue and the frame rate went mad! Is there any way to calculate when a sprite has finished an animation loop?
Yeah compression can be very slow ! The next version will include faster compression algorithm so you will be able to keep compression and good frame rate ;)
About the animation loop, the sprite definition contains everything to define how the sprite will animate but rescomp always assume classic loop animation. If you want to interrupt the "auto animation" just set the timer field to 0 :

Code: Select all

sprites[0].timer = 0
so the sprite engine won't change frame automatically.
Then to know if you are of the last animation frame you can use this :

Code: Select all

// last sequence animation frame ?
if (sprite->seqInd == (sprite->animation->length - 1)) // do something
The thing is that you can even build your own 'Animation' and 'SpriteDefinition' structures to have finer control of the auto animation from the Sprite Engine, by default rescomp generate simple looping animation in these structures but they support more than that (just read the doxygen doc about them).

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Removing a sprite from screen

Post by matteus » Fri Sep 18, 2015 6:06 pm

Thanks for this Stef! I'll look to modify my code to reflect this :)

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Removing a sprite from screen

Post by matteus » Tue Sep 22, 2015 2:36 pm

Hey Stef,
You refer to the last animation frame as this:

Code: Select all

// last sequence animation frame ?
if (sprite->seqInd == (sprite->animation->length - 1)) // do something
I can't access the sprite as it's in the sprite array, so how'd I get around this?

matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Re: Removing a sprite from screen

Post by matteus » Tue Sep 22, 2015 2:46 pm

Code: Select all

if (sprites[0].seqInd == (sprites[0].animation->length - 1)) {
okay sorted ;)

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

Re: Removing a sprite from screen

Post by Stef » Tue Sep 22, 2015 8:10 pm

yeah it depends about how you access it, in my example it was as if i did first :

Code: Select all

Sprite *sprite = &sprites[0];

Post Reply