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 6 ■ The Foundation of Game Design: The <strong>Java</strong>FX Scene Graph and the InvinciBagel Game Infrastructure<br />

As Figure 6-10 shows, the code is error free, because you have copied the four PNG files into your project’s /src<br />

folder. You do not need the other lines of code (ImageView object instantiation, .setImage()), because you will be<br />

using the splashScreenTextArea ImageView object to hold these last two Image objects. Thus, you are saving on Scene<br />

Graph Node objects used, as you are using a single ImageView Scene Graph Node object to display three different<br />

Image objects (overlays), based on button events.<br />

Figure 6-10. Adding legalLayer and scoresLayer Image object instantiations to add the other image composite plates<br />

This means that the splashScreenTextArea.setImage() method calls you will make off the<br />

splashScreenTextArea ImageView object will be placed inside the ActionEvent EventHandler programming<br />

constructs for the three Button objects that trigger image composite overlays when they are clicked. The fourth Button<br />

object will start up game play, so, for now, you will just have a <strong>Java</strong> comment in that button event-handling structure,<br />

making it an “empty” logic structure. Now, let’s take a look at how to finish coding these EventHandler constructs so<br />

that you can finish this UI design and get on with creating the game play engines mentioned earlier.<br />

Interactivity: Wiring the InvinciBagel Buttons for Use<br />

You need to replace the system writing to the console code in all these duplicated button event-handling structures<br />

with calls to the .setImage() method so that you can set the image-compositing plate ImageView to the Image object<br />

that holds the digital image asset you want to overlay the InvinciBagel backplate artwork created by Pat Harrington.<br />

You have already written this code construct twice in the createSplashScreenNodes() method, so you can copy the<br />

line of code directly above the two Image object instantiations you just wrote, if you want a shortcut.<br />

The .setOnAction() event-handling <strong>Java</strong> code structures would therefore look like this:<br />

helpButton.setOnAction(new EventHandler() {<br />

@Override<br />

public void handle(ActionEvent event) {<br />

splashScreenTextArea.setImage(instructionLayer);<br />

}<br />

});<br />

140<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!