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


Summary


In this eighth chapter, we got your hands into our JavaFXGame.java code by refining your actual top-level
user interface design for our game, as well as outlining the underlying game engine component design
and figuring out the most efficient Scene Graph Node design using fewer than a dozen nodes to implement
the majority of the top-level game user interface structure. You got back into Java game programming by
redesigning the existing JavaFXGame.java bootstrap Java code, which was originally created for you by
NetBeans 9 in Chapter 6. Since the NetBeans 9–generated Java 9 code design was not optimal for your
purposes, you rewrote it significantly to make it more modular, streamlined, and organized.
You did this by creating two new Java methods: .createBoardGameNodes() and
.addNodesToSceneGraph(). You did this so you could modularize your Scene Graph Node creation
process and also so that you could modularize the adding of the two Parent branch Node and five Control
leaf Node objects to your Scene Graph root, which in this case happens to be the Group Node object. Under
that you have your StackPane branch Node named uiLayout, which you are using for its multilayer UI object
compositing capability, and a Group branch Node named gameBoard, which you will be using to hold the
i3D game object hierarchy that you will be building during the remainder of this book.
You learned about some of the JavaFX classes that we’re going to implement in these new methods.
These included a Pos class and an Insets class from the javafx.scene.geometry package, the VBox class
from the javafx.scene.layout package, and the Group class from the javafx.scene package. You coded your
new .createBoardGameNodes() method that instantiated and configured the VBox object using the Inset
object, the StackPane uiLayout branch Node object, the Group gameBoard branch Node object, and your
five UI Button Control leaf Node objects.
Once all of your Scene Graph Nodes were instantiated and configured, you were able to then construct
your .addNodesToSceneGraph() method to add your Scene Graph Node objects to your Group root object.
You did this so that the correct Scene Graph Node hierarchy would be displayed inside of your Stage object,
which will reference and load your Scene Graph root Group Node object and the hierarchy that we are
building underneath it.
Finally, you created the other four Button UI Control objects and added ActionEvent EventHandler
program logic. This completed our programming tasks for this chapter that are related to setting up your
Scene Graph hierarchy and user interface design infrastructure for the JavaFXGame.java Java 9 game
application.
Once this was all coded, you tested your top-level Java 9 game application user interface design and
Scene Graph hierarchy in NetBeans 9.
In the next chapter, you are going to add cool digital image assets to your user interface design and work
on the positioning and alignment, as well as getting everything working with your UI Button objects.

Free download pdf