JavaFX Path Transition

It allows the node to animate through a specified path over the specified duration. In JavaFX, the path is defined by instantiating the class javafx.scene.shape.Path.

The translation along this path is done by updating the x and y coordinate of the node at the regular intervals. The rotation can only be done in the case when the orientation is set to be OrientationType.ORTHOGONAL_TO_TANGENT.

In JavaFX, the class javafx.animation.PathTransition represents the path transition. We need to instantiate this class in order to create an appropriate path transition.

Properties

The properties of the class along with the setter methods are described in the following table.

Property Description Setter Methods
duration This property is an object type of the class Duration. This represents the lifespan of the transition. setDuraton(Duration duration)
node This is an object of the class Node. This represents the node onto which the transition will be applied. setNode(Node node)
orientation This is a object type property referenced by PathTransition.OrientationType. It represents the upright orientation of the node along the path. SetOrientation(PathTransition.OrientationType orientation-type)
path This is an object type property of the class Shape. It specified the shape through which the outline of the animated path undergoes. setPath(Shape shape)

Constructors

There are three constructors in the class.

  1. public PathTransition() : Creates the instance of the Path Transition with the default parameters
  2. public PathTransition(Duration duration, Shape path) : Creates the instance of path transition with the specified duration and path
  3. public PathTransition(Duration duration, Shape path, Node node) : Creates the instance of the PathTransition with the specified duration, path and the node.

Example

In the following example, we have created a polygon and applied the path transition on it which is simulating the path of a pendulum.

Output:


JavaFX Path Transition
Next TopicJavaFX 3D Shape




Contact US

Email:[email protected]

JavaFX Path Transition
10/30