22.9 Frame-by-Frame Animation with AnimationTimer

A third way to implement JavaFX animations is via an AnimationTimer (package javafx.animation), which enables you to define frame-by-frame animations. You specify how your objects should move in a given frame, then JavaFX aggregates all of the drawing operations and displays the frame. This can be used with objects in the scene graph or to draw shapes in a Canvas. JavaFX calls the handle method of every AnimationTimer before it draws an animation frame.

For smooth animation, JavaFX tries to display animation frames at 60 frames per second. This frame rate varies based on the animation’s complexity, the processor speed and how busy the processor is at a given time. For this reason, method handle ...

Get Java How to Program, Early Objects, 11th Edition 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.