Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 8 ■ JavaFX 9 SCene Graph hierarChy: a Foundation For Java 9 Game deSiGn


The Game Engine class, which I’ll call GamePulse.java, is the primary class that creates an
AnimationTimer object that processes your game logic at a high level based on pulse events that continually
trigger the gameplay loop. This loop, as you know, will call a handle() method that will in turn contain
method calls that will ultimately access your other classes that you will be creating to manage 3D geometry
(sprite engine), move the 3D objects around the screen (actor engine), detect collision (collision engine),
apply game logic after all collisions have been detected (logic engine), and apply the forces of physics to
provide realistic effects, such as friction, gravity, and wind (physics engine) to your gameplay. During the
remainder of this book you will be building some of these engines, which will be used to create the gameplay
experience for your players. We’ll logically stratify chapter topics based on each of the engines and what they
need to process, so everything is structured logically from a learning, as well as a coding, perspective.


JavaFX Scene Graph Design: Minimizing UI Nodes


The trick to minimizing the Scene Graph is to use as few Nodes as possible to implement a complete UI
design, and as you can see in Figure 8-3, I’ve accomplished this with one Group root Node object, one
StackPane layout “branch” Node object, one VBox branch Node object, and eight leaf (children) nodes
(one TableView, one ImageView, one TextFlow, and five Button UI controls). As you will see when we get
into coding the Scene Graph next, I will use only 12 objects and import only 12 classes to make the entire
top-level UI for the JavaFXGame class that we designed in the previous section a reality. The TableView and
TextFlow objects will be overlaid on top of the ImageView object, which contains the background imagery
for the UI design. This TableView object will be added later in the book and will be updated with code from
the Score Engine, shown in Figure 8-2, which you’ll be coding in a future chapter.


The ImageView backplate will contain the BoardGame artwork, and you can use the ImageView
container to hold different digital image assets, if you want. In this way, based on your ActionEvent objects,
processing clicks on Button controls, you can use different background image assets for each of the
information screens. The VBox Parent UI layout container will control the layout (spacing) for your five
Button controls. There is also the Inset object, which you will create to hold the UI button Padding values to
fine-tune how the Button objects align, relative to each other.


Figure 8-3. Game Scene Graph Node hierarchy, objects that Nodes contain, and new media assets they
reference

Free download pdf