Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 9 ■ JavaFX 9 User InterFaCe DesIgn: the Front enD For Java 9 game DesIgn


Instantiating the Compositing Layers: .createBoardGameNodes()


Since you have already declared the boardGameBackPlate ImageView and infoOverlay TextFlow and coded
the import statements for these classes in Chapter 8 , the next thing that you will need to do is to instantiate
them into objects using the Java new keyword along with their basic (empty parameter list) constructor
methods. You will do this in your createBoardGameNodes() method to keep things highly organized. To
mirror the Scene Graph hierarchy, you will instantiate them after the StackPane and before the VBox since
that will be the compositing (layer) order you will be using. As you can see in Figure 9-2, the Java code is
error-free, and you have a SceneGraph root, i3D gameBoard branch, and UI layout branch instantiated using
only a root and three branch Node objects in system memory, including one Group Node, a StackPane, and
a VBox (the Insets object is a utility object and not a SceneGraph Node).


If you count the Scene object holding the SceneGraph, there are five game organization objects in
memory. Add to this the Stage object, which was created using the .start() method, and your Application
object, created by the JavaFXGame class extends Application declaration, and you have created the top-level
infrastructure for your pro Java 9 games development using a mere seven objects in system memory. With
the ImageView and TextFlow displays, we are still under ten objects in system memory. Once we load your
five Image objects with digital image assets and set up five UI Button objects, you still have fewer than 20
objects in memory, which is still quite well optimized. You will also be adding eight Text objects later during
the chapter, but these are not pixel-centric, so they will not take up much memory footprint at all. We’ll also
be using some utility objects, like Insets, but even with those you’ll still be under 30 objects before you start
adding the core 3D objects that will make up your i3D BoardGame. Let’s add your ImageView and TextFlow
to the Scene Graph next, placing them behind the VBox UI Button bank so they render first.


Figure 9-2. Instantiate boardGameBackPlate and infoOverlay objects inside of your
createBoardGameNodes() method

Free download pdf