Game Development Reference
In-Depth Information
Many new developers are confused by the “Animation” part of this class name; do not
assume that this Timer class is for Animation; it is, at its core, for timing purposes.
This class is the lowest-level class in the javafx.animation package, in terms of access-
ing a JavaFX pulse timing system, and essentially serves just to access the pulse timing
system. Absolutely everything else is stripped away.
The AnimationTimer class is therefore the class that will provide you with the least
system overhead (memory used) to implement. At the full 60FPS speed, it will have
the highest performance, assuming that all the code inside the .handle() method is well
optimized. This is the class to use for a fast, high-dynamics game, such as an arcade
game or a shooter game. For this reason, this is the class that you are going to use for
your game, as you can continue to build a game engine framework and add features
without running out of power.
You will use the lowest-level approach throughout this topic just in case you are
pushing your Java 8 game development to the very limit and are creating a highly dy-
namic, action-filled game. The JavaFX AnimationTimer superclass is perfect for this
type of game application, as it processes its .handle() method on every single JavaFX
pulse event. A pulse event is currently throttled at 60FPS, the standard frame rate (also
called a refresh rate) for professional action games. You will subclass your
GamePlayLoop.java class from the AnimationTimer superclass.
Interestingly, most modern iTV LCD, OLED, and LED display screen products
also update at this exact refresh rate (60Hz), although newer displays will update at
twice this rate (120Hz). Displays with a 240Hz refresh rate are also coming out, but be-
cause these 120Hz and 240Hz refresh rate displays use an even multiple (2× or 4×) of
60Hz, 60FPS is a logical frame rate for developing games for today's consumer elec-
tronics devices. Next, let's implement the GamePlayLoop.java class in your game,
which will subclass AnimationTimer to access pulses.
Creating a New Java Class:
GamePlayLoop.java
Let's use the AnimationTimer superclass from the javafx.animation package to create a
custom GamePlayLoop class (and, eventually, object) and the required .handle() meth-
od to process your game play calculations. As Figure 7-2 demonstrates, this is done in
NetBeans 8.0 by right-clicking the invincibagel package folder in your Projects hier-
archy pane. This will show NetBeans where you want the new Java class to be placed
after it is created.
 
Search WWH ::




Custom Search