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 />

Scene Graph Code: Optimizing Your Current InvinciBagel Class<br />

I know you are eager to work on the InvinciBagel class code, so let’s clean up, organize, and optimize the existing <strong>Java</strong><br />

code to implement this top-level UI screen design. First, put the object declaration and naming <strong>Java</strong> code at the top<br />

of the InvinciBagel class. This is more organized, and all the methods that are inside your class will be able to see and<br />

reference these objects without using <strong>Java</strong> modifier keywords. As you can see in Figure 6-4, these include your existing<br />

scene Scene object, root StackPane object, and btn Button object (which I am renaming gameButton). I added three<br />

other Button objects, named helpButton, scoreButton, and legalButton, all declared and named using a single<br />

line of <strong>Java</strong> code, as well as two ImageView objects, named splashScreenbackplate and splashScreenTextArea.<br />

You also need to create four Image objects to hold digital image assets, which will be displayed in the ImageView<br />

nodes; I have named these splashScreen, instructionLayer, legalLayer, and scoresLayer and declared them,<br />

using one compound <strong>Java</strong> statement. Finally, you declare and name the buttonContainer VBox object and the<br />

buttonContainerPadding Insets object. NetBeans will write import statements for you, so long as you use the<br />

Alt+Enter keyboard shortcut, selecting the correct javafx package and class path. The imports are shown at the top of<br />

the figure.<br />

Figure 6-4. Declaring and naming the 14 objects that will make up your Scene Graph hierarchy at the top of the class<br />

You will be taking a look at all these <strong>Java</strong>FX classes in detail in this chapter so that you learn what they are used<br />

for and what they can do for your <strong>Java</strong> applications.<br />

www.it-ebooks.info<br />

127

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

Saved successfully!

Ooh no, something went wrong!