28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 17 ■ Enhancing Game Play: Creating a Scoring Engine, Adding Treasure and an Enemy Auto-Attack Engine<br />

Before we can use this scoreFont Font object to style the scoreText Text object, we will need to add this scoreText<br />

Text Node object to the <strong>Java</strong>FX Scene Graph by using the root.getChildren().add(scoreText); <strong>Java</strong> statement,<br />

which is shown highlighted in Figure 17-4. If you forget to do this, you will see only white on your game screen after<br />

you click the PLAY GAME Button!<br />

Figure 17-4. Add the scoreText Text Node object to the <strong>Java</strong>FX Scene Graph, using a .getChildren().add() method chain<br />

The next step, now that we can see the Text object in the Scene, is to instantiate the scoreFont Font object using<br />

the <strong>Java</strong> new keyword and a Font(String fontName, int fontSize) constructor method call. The <strong>Java</strong> statement to<br />

accomplish this is shown highlighted in Figure 17-5, and should look like the following:<br />

scoreFont = new Font("Verdana", 20);<br />

Figure 17-5. Instantiate scoreFont object with a <strong>Java</strong> new keyword and Font(String fontName, int fontSize) constructor<br />

396<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!