Game Development Reference
In-Depth Information
name of this class may be somewhat misleading if you are mentally grouping the class
in with the Animation, Interpolator, KeyFrame, and KeyValue classes that occupy the
javafx.animation package with it, as is has no relation to these classes whatsoever!
Like the Transition class, the AnimationTimer class has been declared a public ab-
stract class. Because it is an abstract class, it can only be used (subclassed or extended)
to create AnimationTimer subclasses. Unlike the Transition class, it has no subclasses
that have been created for you; you have to create your own AnimationTimer sub-
classes from scratch, which we will be doing later on in the topic to create our
GamePlayLoop.java class.
The AnimationTimer class is deceptively simple, in that it has only one method that
you must override or replace, contained in the public abstract class: the .handle() meth-
od. This method provides the programming logic that you want to have executed on
every frame of the JavaFX engine's stage and scene processing cycle, which is optim-
ized to play at 60FPS (this is perfect for games). JavaFX uses a pulse system, which is
based on the new Java 8 nanosecond unit of time (previous versions of Java used mil-
liseconds ).
JavaFX Pulse Synchronization: Asynchronous Processing for
Scene Graph Elements
A JavaFX pulse is a type of synchronization ( timing ) event , one that synchronizes the
states of the elements that are contained within any given Scene Graph structure that
you create for your JavaFX applications (games). The pulse system in JavaFX is ad-
ministered by the Glass Windowing Toolkit. Pulse uses high-resolution (nanosecond)
timers, which are also available to Java programmers using the System.nanoTime()
method, as of the Java 8 API.
The pulse management system in JavaFX is capped or throttled to 60FPS . This is
so that all the JavaFX threads have the “processing headroom” to do what they need to
do. A JavaFX application will automatically spawn up to three threads, based on what
you are doing in your application logic. A basic business application will probably only
use the primary JavaFX thread , but a 3D game will also spawn the Prism rendering
thread , and if that game uses audio or video, or both, which it usually will, it will
spawn a media playback thread as well.
You will be using audio, 2D, 3D, and possibly video in the course of your game de-
velopment journey, so your JavaFX game application will certainly be multithreaded!
As you will see, JavaFX has been designed to be able to create games that take advant-
Search WWH ::




Custom Search