Game Development Reference
In-Depth Information
Instead of just having a number on the right side of the UI Button bank (HBox), let's
add a Text label that says
SCORE:
to the front of the scoreText Text object. We will
create a scoreLabel Text object and use the same Font object that we created in the pre-
vious section to style that Text object. I am going to change the numeric part of the
score text to be blue, using the
scoreText.setFill(Color.BLUE);
Java state-
ment, and make the SCORE: label black, using the following Java code, which can also
be seen in
Figure 17-7
:
scoreText
.setFill
(
Color.BLUE
);
scoreLabel =
new
Text();
scoreLabel
.setText
("
SCORE:
");
scoreLabel
.setLayoutY
(385);
scoreLabel
.setLayoutX
(445);
scoreLabel.setFont(scoreFont);
scoreLabel
.setFill
(
Color.BLACK
);
Figure 17-7
.
Add the scoreLabel object instantiation and configuration method calls underneath the scoreText object
As you can see in
Figure 17-8
, you need to remember to add this second scoreLabel
Text Node to the Scene Graph root object, which used to be a StackPane, but which is
now a
Group
object. This is done using a method chain, that you should be getting
quite familiar with by now:
root.getChildren().add(scoreLabel);
and