Page 1 of 1

I Need tips with animations

Posted: Thu Aug 22, 2019 4:18 pm
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!

Re: Need tips with animations

Posted: Thu Aug 22, 2019 8:18 pm
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.

Re: I Need tips with animations

Posted: Thu Aug 22, 2019 8:39 pm
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] ++;
		}
	}

Re: I Need tips with animations

Posted: Fri Aug 23, 2019 8:04 am
by Stef
Looks like a bit complicated but so you want to hide it after animation or just stay on last frame ?

Re: I Need tips with animations

Posted: Fri Aug 23, 2019 12:29 pm
by cloudstrifer
I want to show the defeat animation (6 frames) one time and hide the sprite.

Re: I Need tips with animations

Posted: Fri Aug 23, 2019 2:51 pm
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 :)

Re: I Need tips with animations

Posted: Fri Aug 23, 2019 5:33 pm
by cloudstrifer
Thank you!