28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Figure 17-7. Add the scoreLabel object instantiation and configuration method calls underneath the scoreText object<br />

As you can see in Figure 17-8, you need to remember to add this second scoreLabel Text Node to the Scene<br />

Graph root object, which used to be a StackPane, but which is now a Group object. This is done using a method chain,<br />

that you should be getting quite familiar with by now: root.getChildren().add(scoreLabel); and notice that the<br />

addNodesToStackPane() method is beginning to see more use now that we are adding more UI elements to the game.<br />

Even though the gameScore variable will be updated dynamically during game play, these Text objects will be static in<br />

nature, since they are declared, instantiated, configured, and positioned at start-up, just like your other UI elements.<br />

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

398<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!