Game Development Reference
In-Depth Information
The JavaFX TimeLine Class: An Animation Subclass for Property
Timeline Management
The JavaFX Timeline class is a subclass of the JavaFX Animation superclass, so its in-
heritance hierarchy starts with the Java 8 masterclass, java.lang.Object, progressing
down to the Timeline class, as follows:
> java.lang.Object
> javafx.animation.Animation
> javafx.animation. Timeline
A Timeline object can be used to define a special kind of Animation object that is
composed of JavaFX values (properties) of the object type WritableValue . Because all
JavaFX properties are of that type, this class can be used to animate anything in
JavaFX, which means that its use is limited only by your imagination.
As mentioned earlier, Timeline animations are defined using KeyFrame objects,
created via the KeyFrame class, which both creates and manages these objects. A
KeyFrame object is processed by a Timeline object, according to a time variable (ac-
cessed via KeyFrame.time ) and properties to be animated, which are defined using the
KeyFrame object's values variable (accessed via KeyFrame.values ).
It is important to note that you need to set up your KeyFrame objects before you
start running the Timeline object, as you cannot change a KeyFrame object within a
running Timeline object. This is because it is put into system memory once it has been
started. If you want to change a KeyFrame object in a running Timeline object in any
way, first, stop the Timeline object; then, make the change to the KeyFrame; and, fi-
nally, start the Timeline object again. This will reload the Timeline object and its re-
vised KeyFrame objects into memory with their new values.
The Interpolator class interpolates these KeyFrame.values in the Timeline object,
based on the timeline direction . Interpolation is a process of creating in-between (or
tween) frames, based on the beginning and ending values. In case you are wondering
how the direction is inferred, it is kept in the rate and the read-only currentRate prop-
erty of the Animation superclass (which is a part of the extended Timeline subclass).
Inverting the value of the rate property (i.e., making it negative ) will reverse
(toggle) the playback direction; the same principle holds when reading the currentRate
property (a negative value signifies the reverse, or backward, direction). Finally, the
KeyValue class (object) is used to hold the values inside the KeyFrame object.
Search WWH ::




Custom Search