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

Adding UI Backplate to Scene Graph: addNodesToSceneGraph()


For the ImageView compositing layer and the TextFlow information plate to be on top of the Scene,
3D gameBoard, and StackPane but behind the VBox Button bank, you will need .getChildren().add()
method calls off of the uiLayout StackPane object, after the root method calls, and before the uiContainer
method call. This is shown in Figure 9-3 and will use the following two Java statements inside of your
addNodesToSceneGraph() method structure:


uiLayout.getChildren().add(boardGameBackPlate); // Add ImageView backplate behind TextFlow Node
uiLayout.getChildren().add(infoOverlay); // Add TextFlow information overlay second


Since a Button object can’t be positioned individually, I had to use the VBox class, along with an Insets
class, to contain and position a vertical bank of Button controls. Now we are ready to code our two asset-
loading methods.


Asset Load Methods: loadImageAssets() and createTextAssets()


The next thing that we want to do to keep things organized as we create this game over the course of the
book is to create another two dedicated methods for loading Image object assets and creating Text object
assets. This creates a dedicated “method-based work process” for adding elements to your game. Instantiate
in .createBoardGameNodes(), add to SceneGraph in .addNodesToSceneGraph(), reference Image objects
in .loadImageAssets(), and create Text objects in .createTextAssets(). As you can see in Figure 9-4, I have
placed these two new method calls at the top of the .start() method, as well as having NetBeans create empty
methods for them, which we’ll add Java code to, as we add assets to your game. I placed these at the top of


Figure 9-3. Add boardGameBackPlate and infoOverlay to your Scene Graph in the addNodesToSceneGraph()
method

Free download pdf