Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 14 ■ 3D MoDel hierarChy Creation: Using priMitives to Create a gaMe BoarD


Your reconfigured addNodesToSceneGraph() method statements will now number six Java statements,
and your gameBoard SceneGraph hierarchy, from root to game board squares, now spans three Java 9
statements, which should look like the following Java statements inside of the addNodesToSceneGraph()
method, as shown highlighted in yellow and blue at the middle (with related declarations also highlighted
the top) of Figure 14-7:


root.getChildren().addAll(gameBoard, uiLayout);
gameBoard.getChildren().addAll(Q1, Q2, Q3, Q4);
Q1.getChildren().add(Q1S1);


Next, let’s add the q1 Box game board center quadrant, which will be the parent to the Q1S1 game
board square; thus, this is the next logical thing to add. Since you have already declared the q1 through q4
Box objects at the top of your class, shown in Figures 14-6 through 14-8, you can add this q1 object to your
Q1 branch node first, or you can instantiate it first, in the createGameBoardNodes() method with a 300,
5, 300 (X, Y, Z) parameter, and then add it to the addNodesToSceneGraph() method later, as you can see in
Figure 14-8 and in the following Java code:


Q1.getChildren().addAll(q1, Q1S1); // In addNodesToSceneGraph() method body
q1 = new Box( 300 , 5, 300 ); // In createGameBoardNodes() method body


Figure 14-7. Replace a Q1S1 reference in the gameBoard node builder with Q1 through Q4, and add a Q1
node builder

Free download pdf