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


Preparing to Position Gameboard SceneGraph Nodes


Before we get into positioning 4 quadrants and 20 squares around their perimeter, let’s put the infrastructure
in place for the rest of the SceneGraph and all of the texture maps for the shader (PhongMaterial) to use. Add
the other three Q2 through Q4 SceneGraph Group nodes to your addNodesToSceneGraph() method using
cut and paste, as shown highlighted in light blue in Figure 14-10. Notice that you can use the .getChildren().
addAll() method chain even if you have only one Node subclass object element in the List! Your Java
statements will look like the following:


Q2.getChildren().addAll(q2);
Q3.getChildren().addAll(q3);
Q4.getChildren().addAll(q4);


While we’re at it, create the other three q2 through q4 game board center quadrants so that we can add
them to the Q2 through Q4 node construction statements. Again, since these objects are declared at the top
of your class, you can construct these statements in any order that you want; just don’t use Run ➤ Project
to render the Scene, as you won’t see the objects until they are instantiated and added to the SceneGraph
hierarchy. The Box instantiation Java code should look like the following, as shown at the bottom of
Figure 14-10:


q2 = new Box(300, 5, 300);
q3 = new Box(300, 5, 300);
q4 = new Box(300, 5, 300);


Figure 14-10. Instantiate your other three quadrant Box primitives and your other three quadrant branch
node objects

Free download pdf