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

Testing the InvinciBagel Application: Pulse the Scene Graph<br />

Click the green Play arrow at the top of the NetBeans IDE, and run the project. This will bring up the window<br />

illustrated in Figure 6-9 (I have removed the <strong>Java</strong> code added in Chapter 4, demonstrating how to create a windowless<br />

application). So, you have window “chrome” back, at least for now. As you can see, you are getting a very good result,<br />

using only a dozen import statements (external classes), a few dozen lines of <strong>Java</strong> code, and a half a dozen child nodes<br />

below the Scene Graph root (StackPane) object. As you can see, <strong>Java</strong>FX does a great job of compositing the backplate,<br />

composite image overlays, and button bank overlay into one seamless, professional result!<br />

Figure 6-9. Run the InvinciBagel application, and make sure that the StackPane compositing class is working correctly<br />

Because you only copied and pasted the EventHandler routines for each button, and changed your Button<br />

objects’ names but not the code inside these routines, the Button objects will still work properly (writing text to the<br />

console) and not cause compiler errors. However, they will not do what you want them to do, which is to change an<br />

image overlay so that the panel on the left-hand side of the design holds a title and text that you want it to show a user.<br />

This will be done using a call to the .setImage() method, which will set the splashScreenTextArea ImageView<br />

object to the instructionLayer, scoresLayer, or legalLayer Image object, based on which Button UI control is clicked by<br />

the user. You cannot implement this event-handling code until you add the last two Image object instantiations!<br />

Finishing an InvinciBagel UI Screen Design: Add Images<br />

Let’s finish with the createSplashScreenNodes() method by adding two more lines at the end of the method that<br />

add two more Image objects, referencing the invincibagelcreds.png and invincibagelscores.png 32-bit PNG32<br />

digital image assets. This is done by employing the following two lines of <strong>Java</strong> object instantiation code using the new<br />

keyword:<br />

legalLayer = new Image( "/invincibagelcreds.png", 640, 400, true, false, true );<br />

scoresLayer = new Image( "/invincibagelscores.png", 640, 400, true, false, true );<br />

www.it-ebooks.info<br />

139

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

Saved successfully!

Ooh no, something went wrong!