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 ...
Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.