Game Development Community

Query current animation?

by Jason McIntosh · in Torque Game Builder · 03/01/2005 (10:21 pm) · 10 replies

Is there a way to find out the current animation an AnimatedSprite2D is playing?

#1
03/02/2005 (1:28 am)
I haven't added those calls but the info is there and would only be a couple of lines of code.

It's probably a good idea so I'll add it to the list.

- Melv.
#2
03/02/2005 (5:23 am)
That would be great, because it will allow me to avoid an issue where a non-cycling animation ends up playing over and over due to the "play last animation" behavior. What happens is, onCollision() plays a one-time animation, but if there's another collision during that animation, it plays again and its previous play becomes the "last played" animation, and so ends up getting stuck there and never going back to the real "last played" animation. (Still with me?) I can avoid it by checking for the current animation and not playing it again if it's already being played (thus it will correctly remember the previous animation).

That's the long-winded way of saying "thank you, I'm looking forward to that feature." :)
#3
03/02/2005 (5:46 am)
@Jason: Yeah, cool. Stuff like that would always be in the hands of the developer as there just too many scenarios to guard against otherwise. I've added that to the list. Other datablocks will have certain stuff added as well.

- Melv.
#4
03/02/2005 (7:15 am)
For now you can just use a variable that is set when you play the animation if you choose :)
#5
03/02/2005 (7:37 am)
Here is a workaround


function fxAnimatedSprite2D::playAnim(%this, %anim)
{
	%this.currentAnim = %anim;
	%this.playAnimation(%anim);

}

so instead of using
$player.playAnimation(thisAnimation);

use $player.playAnim(thisAnimation);

then to get the current animation reference

$player.currentAnim;

to see it
echo($player.currentAnim);
#6
03/02/2005 (8:33 am)
Ok, well threw together a couple bigger functions

if you use this playAnim it will keep a record of the last 5 animations (as you can see you can change %this.animLimit to whatever you want though)

you then use .getLastAnim() to get the last anim... and if you want previous animations you just throw an offset number in there....
for example

echo($player.getLastAnim(1));

this will display which animation was one animation back

a bit of looping in here that keeps the limit at whatever you set it as and when it goes over it kicks each value back once so everything is stored correctly


function fxAnimatedSprite2D::playAnim(%this, %anim)
{
	%this.animLimit = 5;
	
	if(%this.playAnimation(%anim))
      {

		if(%this.animCount > %this.animLimit)
		{
			%this.animCount--;
			for(%i=0;%i<(%this.animLimit - 1);%i++)
				%this.lastAnim[%i] = %this.lastAnim[%i+1];
			
		} 
	
		if(!%this.animCount)	
			%this.animCount = 1;

		%this.currentAnim = %anim;
		%this.lastAnim[(%this.animCount - 1)] = %anim;
		%this.animCount++;
	
      }
}

function fxAnimatedSprite2D::getLastAnim(%this, %offset)
{
	if(%offset >= %this.animCount)
	{
		echo("Do not have anim that far back");
	} else
	{
		return %this.lastAnim[(%this.animCount - 1) - %offset];
	}
}
#7
03/02/2005 (10:33 am)
@Matthew: Yeah, I am storing the animation similar to what you did as a workaround. Thanks for the code and the reply!
#8
03/20/2005 (7:17 am)
FYI

Added the following functions to fxAnimatedSprite2D...

getAnimationName()
getAnimationFrame()
getIsAnimationFinished()

Expect these in the next update.

Note that the animation system will be much more powerful than it currently is, especially in terms of queueing and interpolation.

- Melv.
#9
03/20/2005 (7:24 am)
Quote:Expect these in the next update.

That has GOT to be your favorite saying.
Is there an ETA for this mythical 'next update' you speak of so much?
Or even a GTA (Guesstimated Time of Arrival)? =)
#10
03/20/2005 (7:58 am)
Guesstimate is 10 days, maybe sooner.

Got some biggy ones to sort so it's as soon as they get done and we can package and test the changes.

Josh will be posting over the next few days on how we're going to roll out updates etc.

- Melv.