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

As you can see in Figure 14-9, quadrant 1 is underneath game board square 1 and not in a position
where their corners are touching. So, move quadrant 1’s q1 Box object diagonally 225 units. This equates to
the length of the board game square side plus another 50 percent, or 225 units. If you use only 150 units, the
quadrant corner will be centered in the game board square. The code to create this alignment looks like the
following .setTranslateX() and .setTranslateZ() Java method calls, as shown highlighted in yellow and blue in
the middle of Figure 14-11:


private void createGameBoardNodes() {
q1.setTranslateX( 225 );
q1.setTranslateZ( 225 );
Q1S1 = new Box(150, 5, 150);
Q1S1.setMaterial(phongMaterial);
q2 = new Box(300, 5, 300);
q2.setVisible(false);
q3 = new Box(300, 5, 300);
q3.setVisible(false);
q4 = new Box(300, 5, 300);
q4.setVisible(false);
}


Also notice that I have “hidden” quadrants 2 through 4 using the .setVisible(false) method call so that I
can work on quadrant 1’s q1 Box and its five game board square children first, as I am going to do quadrant
1 first to show you the work process I am using, then quadrant 2, then quadrant 3, and so forth. It is useful to
break any complex tasks into subtasks if possible so you don’t get overwhelmed during development. Since
the SceneGraph hierarchy is set to use four board quadrants under the gameBoard branch, this is how I am
going to go about building the game board, one quadrant (in this case, Q1) at a time. Notice my game board
square names also match this, so I have an advantage, as my game board square objects, in this case Q1S1
through Q1S5, match up with the quadrant Group object name Q1. Since I can’t duplicate the Q1 Group
object name for the Box quadrant object name, I have to use a lowercase q1 through q4 for my quadrant
planar primitives, which is fine, as I still know what is going on and because the quadrant portions of the
game board are not nearly as important as the game board squares themselves.


Figure 14-11. Move the q1 quadrant to the X,Z location 225,225 so that it is internal to square Q1S1 with the
corners touching

Free download pdf