I Need tips with animations

SGDK only sub forum

Moderator: Stef

Post Reply
cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

I Need tips with animations

Post by cloudstrifer »

Hi, i need to improve my code.

I need to know two things.

1 - Show an animation just one time, without loop.

Code: Select all

	if(arrEnemyFrame[enemyIndex] == 0)
	{			
		arrEnemies[enemyIndex]->timer = 0;
		SPR_setAnimAndFrame(arrEnemies[enemyIndex], ANIM_PIRATE_DIE, 0);
		arrEnemyFrame[enemyIndex] ++;			
	}
	else
	{
		if (arrEnemyFrame[enemyIndex] == (arrEnemies[enemyIndex]->animation->length))
		{			
			SPR_setVisibility(arrEnemies[enemyIndex], HIDDEN);				
		}
		else
		{
			SPR_nextFrame(arrEnemies[enemyIndex]);
			arrEnemyFrame[enemyIndex] ++;
		}
	}
2 - Show just one frame from animation without play other frames.

Code: Select all

	arrEnemies[enemyIndex]->timer = 0;
	SPR_setAnimAndFrame(arrEnemies[enemyIndex], ENEMY_DIE, 0);	
Thank you for help!
Last edited by cloudstrifer on Thu Aug 22, 2019 8:45 pm, edited 2 times in total.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Need tips with animations

Post by Stef »

You need to pass the timer to 0 after the SPR_update() call :

Code: Select all

SPR_setAnimAndFrame(arrEnemies[enemyIndex], ENEMY_DIE, 0);	
...
// actually update the anim / frame
SPR_update();
// disable auto animation for further SPR_update() call 
arrEnemies[enemyIndex]->timer = 0;
And there is no way to disable loop except putting timer to 0 when you reach last frame of animation.
cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

Re: I Need tips with animations

Post by cloudstrifer »

I found this way to make it works, i don't know if this is the best.

Thanks Stef.

Code: Select all

	if(arrEnemyFrame[enemyIndex] == 0)
	{			
		arrEnemies[enemyIndex]->timer = 0;
		SPR_setAnimAndFrame(arrEnemies[enemyIndex], ANIM_PIRATE_DIE, 0);
		arrEnemyFrame[enemyIndex] ++;			
	}
	else
	{
		if (arrEnemyFrame[enemyIndex] == (arrEnemies[enemyIndex]->animation->length))
		{			
			SPR_setVisibility(arrEnemies[enemyIndex], HIDDEN);				
		}
		else
		{
			SPR_nextFrame(arrEnemies[enemyIndex]);
			arrEnemyFrame[enemyIndex] ++;
		}
	}
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: I Need tips with animations

Post by Stef »

Looks like a bit complicated but so you want to hide it after animation or just stay on last frame ?
cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

Re: I Need tips with animations

Post by cloudstrifer »

I want to show the defeat animation (6 frames) one time and hide the sprite.
Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: I Need tips with animations

Post by Stef »

Then your solution is ok for that but i guess you can simply use a counter which start at defeat time then after some frames (when animation is done) you simply hide the sprite :)
cloudstrifer
Very interested
Posts: 118
Joined: Mon Feb 19, 2018 7:31 pm

Re: I Need tips with animations

Post by cloudstrifer »

Thank you!
Post Reply