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

Set the alignment for the scoreTitle heading in the scoreLayout StackPane using the .setAlignment()
method call with the Pos.TOP_CENTER constant, which will center this crimson SCORE heading at the
top and in the center of the StackPane container. Interestingly, Text object alignment is set in the parent
StackPane container. We can custom-align nonheading Text elements later, using the .setTranslateX() and
.setTranslateY() method calls, off of the Text child objects to fine-tune the alignment within the Score UI
panel as we flesh out this design over the next few pages.
Instantiate the scoreTitle Text object at the bottom of your createScoreNodes() method and then
configure it by using the .setFont() method. Use an Arial Black font face for its bold readability at a large
72 -point font size. Use the .setFill() method call and change the color from Black to Dark Red so that the
Score Title is easily viewable at the top of the Score UI panel. The Java code, shown highlighted at the bottom
of Figure 22-12, looks like the following:


private void createScoreNodes() {
scoreLayout = new StackPane();
scoreLayout.setTranslateX(650);
scoreLayout.setTranslateY(-385);
scoreLayout.setTranslateZ(-75);
scoreLayout.setBackground(new Background(new BackgroundFill(Color.WHITE,
CornerRadii.EMPTY,
insets.EMPTY) ) );
scoreLayout.setPrefSize(360, 654);
scoreLayout.setAlignment(Pos.TOP_CENTER);
scoreTitle = new Text("SCORE");
scoreTitle.setFont( Font.font("Arial Black", 72 ) );
scoreTitle.setFill(Color.DARKRED);
}


Figure 22-13 shows the Run (^) ➤ Project work process to preview how the “SCORE” title works in the
Score pane.
Figure 22-13. Use the Run ➤ Project work process to preview the Score UI panel with its new Dark Red title
heading

Free download pdf