What is an animation?
From a JavaFX point of view, an animation is a change of a property over a period of time; for example:
- If you want an object to move, you need to work with coordinate properties.
- If you want to shrink or enlarge an object, you can use the scale property.
- You can even use the Animation API for objects which don't have a visual representation at all.
You need the following three API classes to create an animation:
KeyFrame
represents a point in timeKeyValue
describes the value the desired property should have at the moment described byKeyFrame
Timeline
collects allKeyFrame
objects and runs the animation, calculating all intermediate values for properties betweenKeyFrame
objects.
In the next section, we will review these concepts with an example.
Animation example
Let's look at the following code and corresponding comments:
// chapter5/basics/BasicAnimation.java
public void start(Stage stage) {
Circle circle = new Circle(50, 150, 50, Color.RED);
// change circle.translateXProperty...