Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 22 ■ SCoring engine: Creating the SCore Ui LayoUt and SCoring the Content

Figure 22-15 shows a Run (^) ➤ Project work process to preview how a Right: heading works in the
Score pane.
Since this particular i3D board game design is for younger children about to enter school, let’s also
include a “Wrong:” score tracking heading and also add some encouragement after each answer, such
as Great Job! or Spin Again. The fastest way to write this code is to copy and paste the scoreRight code,
underneath itself, and change scoreRight to scoreWrong while also changing the color to Red and X, Y
location to -25, 300. This is shown in the following Java 9 code and highlighted in yellow at the bottom of
Figure 22-16:
private void createScoreNodes() {
...
scoreLayout.setPrefSize(360, 654);
scoreLayout.setAlignment(Pos.TOP_CENTER);
scoreTitle = new Text("SCORE");
scoreTitle.setFont( Font.font("Arial Black", 72) );
scoreTitle.setFill(Color.DARKRED);
scoreRight = new Text("Right:");
scoreRight.setFont( Font.font("Arial Black", 72) );
scoreRight.setFill(Color.DARKBLUE);
scoreRight.setTranslateX(-50);
scoreRight.setTranslateY(150);
scoreWrong = new Text("Wrong:");
scoreWrong.setFont( Font.font("Arial Black", 72) );
scoreWrong.setFill(Color.RED);
scoreWrong.setTranslateX(-25);
scoreWrong.setTranslateY( 300 );
}
Figure 22-15. Use a Run ➤ Project work process to preview the Score UI panel with new Dark Blue “Right:”
score heading

Free download pdf