Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 9 ■ JavaFX 9 User InterFaCe DesIgn: the Front enD For Java 9 game DesIgn


In the createBoardGameNodes() method, call the .setBackground() method off the uiLayout object and
pass over a uiBackground Background object, replacing the Background.EMPTY constant, using the code in
Figure 9-12:


uiLayout.setBackground(uiBackground);


Use Run ➤ Project to see if a backplate image is in the background of your StackPane, as shown in
Figure 9-13.


Now we’re ready to add your text layer into your compositing pipeline using the TextFlow and Text
objects.


Using TextFlow: Setting Up Your Information Overlay Object


Open your createTextAssets() method, add two method calls off of each of the playText and moreText
objects, make sure that they use the Color.WHITE constant to fill the font, and select a widely supported
Helvetica font, using its REGULAR font face and setting a large 50 pixels for the font height. Use the
FontPosture helper class (font face constants) to set the playText and moreText objects to use the regular
font style. Add the escape newline, or \n character sequence, inside of the moreText object to split it into
two lines. The new Text objects configuration highlighted in the middle of Figure 9-14 should look like the
following Java code:


playText = new Text("Press the Start Game Button to Start! \n");
playText.setFill(Color.WHITE);
playText.setFont(Font.font("Helvetica", FontPosture.REGULAR, 50));
moreText = new Text("Use other buttons for instructions, \n copyrights, credits and scores.");
moreText.setFill(Color.WHITE);
moreText.setFont(Font.font("Helvetica", FontPosture.REGULAR, 50));


Figure 9-13. Use the Run ➤ Run Project (JavaFXGame) menu sequence to test your new compositing pipeline
Java code

Free download pdf