Game Development Reference
In-Depth Information
will create in memory the Animation object, which will control an animation and its
playback characteristics and life cycle.
The Animation class contains the .play() method, the .playFrom(cuePoint) or
.playFrom(Duration time) method, and a .playFromStart() method. These methods
are used to start playback for the Animation object. There are also the .pause() method,
which can pause the animation playback, and a .stop() method, to stop animation play-
back. The .jumpTo(Duration time) and .jumpTo(cuePoint) methods are used to jump
to predefined positions in an animation.
You can set the animation playback speed (also called the frame rate or frames per
second [FPS]) by using the rate property. The cycleCount property (variable) allows
you to specify how many times an animation will loop , and a delay property lets you
specify a delay time before the animation starts. If your animation is looping, this delay
property will specify the delay time between loops, which can help you create some
realistic effects.
You can specify a seamless animation loop by setting the cycleCount attribute or
property (variable) to INDEFINITE and then using the autoReverse property (set to
false ), or you can use pong (back and forth) animation looping by specifying the true
value for the autoReverse property. You can also set the cycleCount to a numeric
value (use 1 if you want the animation to play only one time) if you do not want the
animation to loop indefinitely.
The .setRate() method sets the animation playback rate property, the .setDelay()
method sets the delay property, and the .setCycleCount() and .setCycleDuration()
methods control the cycling characteristics. There are also similar .get() methods to
“get” the currently set values for these Animation object variables (properties, attrib-
utes, parameters, or characteristics; however you prefer to look at these data fields is
fine).
You can assign an action to be executed when the animation has completed play-
back, using the onFinished property loaded with an ActionEvent object. The action
will be executed when the animation reaches the end of each loop, and, as you can ima-
gine, some very powerful things can be triggered in a game with this particular capabil-
ity.
There are also read-only variables (properties), which you can “poll” at any time to
find the status , currentTime , currentRate , cycleDuration , and totalDuration for
each Animation object. For example, you can use the currentTime property to see the
position of the playback head (frame pointer) at any point in time in the animation
playback cycle.
Search WWH ::




Custom Search