Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 16 ■ 3D Game animation Creation: UsinG the animation transition Classes

Animation has two overloaded constructors, one simple (empty parameter area) one that creates an
empty or unconfigured Animation object and a second that configures the Animation object with a target
frame rate. These constructor methods (their subclass’s constructor method format, as these are not directly
usable in your code) should look like the following Java code:


protected Animation() // Protected: Cannot Be Directly Instantiated
protected Animation(double targetFramerate)


There are literally dozens of methods with which you can control your Animation objects, which, in
the case of this chapter, is going to be the various Transition subclasses. These inherit the methods from the
Animation class, through the Transition class, to the various property transition classes, which we will be
using for Java 9 games.
The autoReverseProperty() method call returns a BooleanProperty defining whether the Animation
object will reverse its direction between (alternating) playback cycles. The currentRateProperty() method
call returns a read-only double variable used to indicate the current speed and direction at which the
Animation object is playing.
A .rateProperty() method call returns a double value speed and direction at which an Animation is
expected to play. A .statusProperty() method call returns a ReadOnlyObjectProperty<Animation.Status>
status of an Animation, and a .currentTimeProperty() method call returns an Animation object’s playback
position. The .cycleCountProperty() returns the number of cycles in an Animation object using an integer
value that represents the cycleCount property.
The .cycleDurationProperty() method returns a read-only variable indicating a duration of one cycle
of the Animation, which is the time it takes to play from time 0.0 to the end of the Animation at the default
rate of 1.0. The .delayProperty() method call returns the duration of the delay property that delays the start
of an Animation object.
A .totalDurationProperty() method call returns a read-only Duration property setting to indicate the
total duration for the Animation object. It is important to note that this value will include all of the animation
repeat cycles.
The .getCuePoints() method call returns an ObservableMap<String,Duration> containing the cue
points for the Animation object. These cue points should be used to mark important positions within the
Animation object. The .getCurrentRate() method call will return the double value for your Animation
object’s currentRate property.
The .getCurrentTime() method call will return the value of the Animation object’s currentTime
property.
The .getCycleCount() method call will return the integer value of the Animation object cycleCount
property, and the .getCycleDuration() method call will return the value of the cycleDuration property. The
.getDelay() method call will return the value of the delay property.
A .getOnFinished() method call will return an EventHandler value of an onFinished
property, and a .getRate() method call will return the double value of the rate property. The .getStatus()
method call will return the Animation.Status value of the status property.
The .getTargetFramerate() method call will return the target frame rate, which is the maximum frame
rate at which the Animation object will run (using frames per second).
The .getTotalDuration() method call will return the Duration value for the totalDuration property.
The .isAutoReverse() method call will return the value of the autoReverse property.
The void .jumpTo(Duration time) method call will jump to a given position in the Animation object,
as will the void .jumpTo(String cuePoint) method call, using a cuePoint parameter rather than a Duration
parameter.
The .onFinishedProperty() method call returns the ObjectProperty<EventHandler>
action to be triggered at the conclusion of the Animation object playback. The void .pause() method call
is used to pause the animation object playback cycle. The void .play() method call will play an Animation
object from its current position, in the direction indicated by the rate property.

Free download pdf