Java Reference
In-Depth Information
Figure 15-6 . Path transition
How It Works
In this recipe, you create a simple application enabling objects to follow a drawn path
on the scene graph. To make things simple, the example uses one shape ( Circle ) that
performs a path transition ( javafx.animation.PathTransition ). The applic-
ation user will draw a path on the scene surface by pressing the mouse button like a
drawing program. Once satisfied with the path drawn, the user releases the mouse
press, which triggers the red ball to follow the path, similar to objects moving through
pipes inside a building.
You first create two instance variables to maintain the coordinates that make up the
path. To hold the path being drawn, create an instance of a
javafx.scene.shape.Path object. The path instance should be added to the
scene graph before the start of the application. Shown here is the process of adding the
instance variable onePath to the scene graph:
// add path
root.getChildren().add(onePath);
 
Search WWH ::




Custom Search