Game Development Community

Pause and Resume Animation

by S. Arul Prakash · in Torque Game Builder · 09/12/2008 (5:09 am) · 6 replies

I'm a beginner to TGB. Plz help me. I'm having a doubt. Plz tell me how to stop a animation? and how to resume a paused animation?

#1
09/30/2008 (4:46 pm)
Well if you're new then you probably want to do it in the editor. It's probably something you'll need to do the script though. Just stop the animation. Get the current frame and save it as an attribute of the object. Then when its time to start it up, just start the animation and use the saved frame number as the starting frame.

I realize this sounds a little complex, but that's about as easy a way as I can think of.
#2
09/30/2008 (5:37 pm)
If your a beginner to TGB, I suggest you look at some tutorials such as the Shooter tutorial and the platformer tutorials, they will give you a basic idea to scripting.
#3
10/01/2008 (5:48 am)
Thanks Peter. I can able to safe the current frame of animation by the help of function getFrame(). But i don know how to start the same animation from that frame. How can we play an animation from a particular frame at run time? Can u plz tell me?
#4
10/01/2008 (1:50 pm)
There's a setAnimation and a playAnimation. The second one has a parameter for the frame number, I think.
#5
10/02/2008 (12:40 am)
Hope this helps you S. Arul Prakash... Basically, the idea is to call an idle animation that is in your Editor when you want the animation to stop. When the key is down, you use setAnimation(Animation Name) to move/play the running animation. When the key is up and you want to stop animating, you use setAnimation(Animation Name), which will be the animation you want to use as an "idle" animation. Using the Adventure package, this is what my player class looks like for stopping/starting animation. As to how you would physically stop an animation from playing if you weren't going to use an idle animation, the only thing I could think of is if you were to get the current animation key, and have it play over and over again in some kind of loop. I believe just using the setAnimation function is the best/most resource friendly way of doing it. If my explanation is not clear enough, please just let me know and I'll try again. Its almost 2:00 AM here, so you get a tired answer to your question=)

function PlayerClass::onLevelLoaded(%this, %scenegraph)
{
$Player = %this;

moveMap.bindCmd(keyboard, "d", "PlayerRight();", "PlayerRightStop();");//Move right
moveMap.bindCmd(keyboard, "a", "PlayerLeft();", "PlayerLeftStop();");//Move lest

}

function PlayerRight()
{
$Player.setAnimation(orc_forward_east_anim);
$Player.setLinearVelocityX($Player.Speed);
}

function PlayerLeft()
{
$Player.setAnimation(orc_forward_west_anim);
$Player.setLinearVelocityX(-$Player.Speed);
}

function PlayerRightStop()
{
$Player.setLinearVelocityX(0);
$Player.setAnimation(orc_idle_east_anim);
}

function PlayerLeftStop()
{
$Player.setAnimation(orc_idle_west_anim);
$Player.setLinearVelocityX(0);
}
#6
10/10/2008 (4:05 am)
Thank you shaz. Now i can able to play animations from particular frame by help of playAnimation()