The Transition Superclass
The abstract javafx.animation.transition.Transition superclass provides a simple framework (based on an internal javafx.animation.Timeline instance) for performing various kinds of animated transitions. To begin, the following list identifies most of this class's variables (additional variables are discussed later):
- action (of type function():Void) identifies the function that's executed at the end of this Transition's duration. The default setting is null.
- autoReverse (of type Boolean) specifies whether this Transition reverses direction on alternate transition cycles. If this variable is set to true, the Transition proceeds forward on the first cycle, backward on the next cycle, and so on. The default setting is false, which means that each cycle proceeds forward from the initial javafx.animation.KeyFrame setting.
- currentRate (of type Number) defines the current direction/rate at which this Transition is played. A positive value indicates the forward direction; a negative value indicates the reverse direction. This variable is read-only.
- duration (of type javafx.lang.Duration) specifies the length (in milliseconds) of each of this Transition's cycles. This variable can only be modified prior to starting this Transition and after this Transition completes. It defaults to 0ms.
- interpolate (of type javafx.animation.Interpolator) specifies the interpolator that's used to calculate intermediate keyframes. The interpolator commonly determines the acceleration and deceleration for each transition cycle. This variable can only be modified prior to starting this Transition and after this Transition completes. It defaults to Interpolator.EASEBOTH.
- node (of type javafx.scene.Node) identifies the node that's the target of this Transition. It defaults to null.
- paused (of type Boolean) indicates whether this Transition is currently paused. This read-only variable initializes to false, becomes true after the pause() function has been called while this Transition is running, and then reverts to false after an explicit call to play(), playFromStart(), or stop(). I'll describe pause(), play(), playFromStart(), and stop() shortly.
- rate (of type Number) defines the direction/rate at which this Transition is played. It defaults to 1.0 for the forward direction/normal rate. For a doubled backward rate, set this variable to -2.0.
- repeatCount (of type Number) specifies the number of transition cycles. It defaults to 1.0, but can be set to Timeline.INDEFINITE for an indefinite number of cycles. The assigned value must be greater than or equal to 1.0.
- running (of type Boolean) indicates whether this Transition is currently running. This read-only variable initializes to false, becomes true after playFromStart() has been called, and reverts to false after this Transition ends, whether naturally or via a call to stop(). This variable's value remains set to true even when paused is set to true.
- time (of type Duration) defines the referenced elapsed time offset within this Transition's timeline. If the timeline is running, it immediately jumps to this time position. Otherwise, the timeline sets the current time position to this value and starts from this point the next time play() is called. This variable defaults to 0ms.
You'll encounter some of these variables as you progress through this article. When we take a look at creating additional transitions, you'll learn about timeline and a few other variables that are not included in the list. For now, consider the following list of transition-control functions:
- public pause(): Void pauses this Transition.
- public play(): Void starts or resumes this Transition.
- public playFromStart(): Void starts this Transition from its initial position and plays it in the forward direction.
- public stop(): Void stops this Transition and resets its play position to the initial position.
These functions behave in a manner similar to that of their counterparts with the same names in the Timeline class. Keep in mind that pause() and stop() have no effect if this Transition isn't currently running. Similarly, the play() and playFromStart() functions have no effect if this Transition is already running.