JavaFX Animation

In general, the animation can be defined as the transition which creates the myth of motion for an object. It is the set of transformations applied on an object over the specified duration sequentially so that the object can be shown as it is in motion.

This can be done by the rapid display of frames. In JavaFX, the package javafx.animation contains all the classes to apply the animations onto the nodes. All the classes of this package extend the class javafx.animation.Animation.

JavaFX provides the classes for the transitions like RotateTransition, ScaleTransition, TranslateTransition, FadeTransition, FillTransition, StrokeTransition, etc.

Basic Transitions

The package javafx.animation provides the classes for performing the following transitions.

SNTransitionDescription
1Rotate TransitionRotate the Node along one of the axes over the specified duration.
2Scale TransitionAnimate the scaling of the node over the specified duration.
3Translate TransitionTranslate the node from one position to another over the specified duration.
4Fade TransitionAnimate the opacity of the node. It keeps updating the opacity of the node over a specified duration in order to reach a target opacity value
5Fill TransitionAnimate the node's fill color so that the fill color of the node fluctuates between the two color values over the specified duration.
6Stroke TransitionAnimate the node's stroke color so that the stroke color of the node fluctuates between the two color values over the specified duration.
7Perform the list of transitions on a node in the sequential order.
8Parallel TransitionPerform the list of transitions on a node in parallel.
9Path TransitionMove the node along the specified path over the specified duration.

Steps for applying Animations

  1. Create the target node and configure its properties.
  2. Instantiate the respective transition class
  3. Set the desired properties like duration, cycle-count, etc. for the transition.
  4. Set the target node on which the transition will be applied. Use the following method for this purpose.
  5. Finally, play the transition using the play() method.





Latest Courses