Game Development Reference
In-Depth Information
You will also be taking a closer look at the overall structure of the entire
javafx.animation package, because you'll need to use one of these classes for your Java
8 game play loop. You will do this by using a diagram of the entire package, so that
you can get an overview of how all its classes interrelate. You will then examine the
class hierarchies among all of the JavaFX Animation classes, in detail. With the excep-
tion of
AnimationTimer
,
Interpolator
,
KeyFrame
, and
KeyValue
, all of these
javafx.animation package classes are subclassed (using the Java extends keyword) us-
ing the JavaFX Animation superclass.
Finally, you will be adding the new
GamePlayLoop.java
class into your invinciba-
gel package, which will be created as a GamePlayLoop object in the InvinciBagel.java
Application subclass, implementing the
timing loop
. This GamePlayLoop class will
contain a
.handle()
method, as well as a
.start()
method and a
.stop()
method, which
will allow you to control your GamePlayLoop
timing events
when the GamePlayLoop
is operational, and to determine when it is latent (stopped or paused).
I will create a diagram that will show the class and object hierarchy for this Invin-
ciBagel game, so that you can start to visualize how these classes that you are coding,
and objects that you are creating, will all fit together. It is almost as if the coding of a
game using Java 8 and JavaFX is in itself a (puzzle) game! Pretty cool stuff.
Game Loop Processing: Harnessing a
JavaFX Pulse
One of the primary questions, even among Oracle employees on the development
teams, is which
design approach
to implementing a
game timing loop
engine should
be used with classes that are contained in the JavaFX animation package (suite of
classes). Indeed, this is precisely what this chapter is all about: using the
javafx.animation
package and its classes, which tap into the
JavaFX pulse event tim-
ing engine
. At the top level of the class hierarchy for the package, shown in
Figure 7-1
,
the
AnimationTimer
and
Animation
classes provide the primary way to grab hold of
these pulse events so that they do your real-time processing for you. In this section, you
will see how they differ and what they have been designed for, including the kinds of
games they should be used for. With the exception of
Interpolator
(motion curve ap-
plication),
KeyFrame
(keyframe definition), and
KeyValue
(keyframe customization),
all the classes in the javafx.animation package can be used to harness pulse events.