O'Reilly logo

JavaFX 2.0: Introduction by Example by Carl Dea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2-3. Animating Shapes Along a Path

Problem

You want to create a way to animate shapes along a path.

Solution

Create an application that allows a user to draw the path for a shape to follow. The main Java classes used in this recipe are these:

  • javafx.animation.PathTransition
  • javafx.animation.PathTransitionBuilder
  • javafx.scene.input.MouseEvent
  • javafx.event.EventHandler
  • javafx.geometry.Point2D
  • javafx.scene.shape.LineTo
  • javafx.scene.shape.MoveTo
  • javafx.scene.shape.Path

The following code demonstrates drawing a path for a shape to follow:

/**  * Working with the Scene Graph  * @author cdea  */ public class WorkingWithTheSceneGraph extends Application {     Path onePath = new Path();     Point2D anchorPt;     /**      * @param args the command ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required