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

Finishing Your GameBoard Construction: Quadrants 2 Through 4


Close your createMaterials() method and reopen your createGameBoardNodes() method. Add the location
statement to the Q1S1 object using Q1S1.setTranslateX( 300 ) to position the first child square where we
want it to be, at the beginning of the quadrant, going in the clockwise direction.
Next, copy and paste your three Q1S1 game board square statements four times underneath themselves
to create the rest of the square objects, which we will also have to reconfigure, as far as X, Z location
parameters go and as far as the shader object referencing is concerned.
Q2S2 only needs to position itself 150 units from the 0,0 origin, because your squares are 150 by



  1. This is done by changing the location method call to .setTranslateX( 150 ). Be sure to also set
    .setMaterial(Shader2) to reference the correct shader that then references (and applies) the diffuse2
    Image object as a diffuseMap property.
    Q2S3 is the only square that doesn’t need repositioning, as it will be at the 0,0 origin. I’ve added
    the method call .setTranslateX( 0 ) in the sample code (but not in NetBeans 9). Be sure to also set
    .setMaterial(Shader3) to reference the correct shader, which then references (and applies) the diffuse3
    Image object as a diffuseMap property.
    Q2S4 only needs to position itself 150 units from the 0,0 origin, but this time, in the Z direction. This is
    done by changing the location method call to .setTranslateZ( 150 ). Be sure to set .setMaterial(Shader4)
    to reference the correct Shader4 object, which then references (and applies) the diffuse4 Image object as a
    diffuseMap property.
    Q2S5 needs to position itself 300 units in the Z direction from 0,0. This is done using a location method
    call to .setTranslateZ( 300 ). Be sure to set .setMaterial(Shader5) to reference the correct Shader5
    object, which then references (and applies) the diffuse5 Image object as a diffuseMap property. The Java
    code, which is also shown highlighted in Figure 14-16, should look like the following:


private void createGameBoardNodes() {
q1.setTranslateX(225);
q1.setTranslateZ(225);
Q1S1 = new Box(150, 5, 150);
Q1S1.setTranslateX( 300 );
Q1S1.setMaterial(Shader 1 );
Q1S2 = new Box(150, 5, 150);
Q1S2.setTranslateX( 150 );
Q1S2.setMaterial(Shader 2 );
Q1S3 = new Box(150, 5, 150);
Q1S3.setTranslateX( 0 ); // This statement can be omitted, as default X location is 0
Q1S3.setMaterial(Shader 3 );
Q1S4 = new Box(150, 5, 150);
Q1S4.setTranslateZ( 150 );
Q1S4.setMaterial(Shader 4 );
Q1S5 = new Box(150, 5, 150);
Q1S5.setTranslateZ( 300 );
Q1S5.setMaterial(Shader 5 );
q2 = new Box(300, 5, 300);
q2.setVisible(false); // Set q2 through q4 quadrant objects to visible=false for now
}

Free download pdf