Since we're talking about the loop()
method, let's start discussing some of the different controls for playing and stopping animations. There are four basic methods we can use:
play("AnimName"):
This method plays the animation once from beginning to end.loop("AnimName"):
This method is similar to play, but the animation doesn't stop when it's over; it replays again from the beginning.stop()
or stop("AnimName"):
This method, if called without an argument, stops all the animations currently playing on the Actor
. If called with an argument, it only stops the named animation.We have some more advanced options as well. Firstly, we can provide option fromFrame
and toFrame
arguments to play or loop to restrict the animation to specific frames.
myActor.play("AnimName", fromFrame = FromFrame, toFrame = toFrame)
We can provide both the arguments, or just one of them. For the loop()
method, there is also the optional argument restart
, which can be set to 0
or 1
. It defaults to 1
, which means to restart the animation from the beginning. If given a 0
, it will start looping from the current frame.
We can also use the getNumFrames("AnimName")
and getCurrentFrame("AnimName")
methods to get more information about a given animation. The getCurrentAnim()
method will return a string that tells us which animation is currently playing on the Actor
.
The final method we have in our list of basic animation controls sets the speed of the animation.
myActor.setPlayRate(1.5, "AnimName")
The setPlayRate()
method takes two arguments. The first is the new play rate, and it should be expressed as a multiplier of the original frame rate. If we feed in .5
, the animation will play half as fast. If we feed in 2
, the animation will play twice as fast. If we feed in -1
, the animation will play at its normal speed, but it will play in reverse.
Experiment with the various animation control methods we've discussed to get a feel for how they work. Load the Stand
and Thoughtful
animations from the animations folder as well, and use player input or delayed tasks to switch between animations and change frame rates. Once we're comfortable with what we've gone over so far, we'll move on.