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

<strong>Java</strong>FX Scene Graph Design: Minimizing UI Nodes<br />

The trick to minimizing the Scene Graph is to use as few nodes as possible to implement a complete design, and,<br />

as you can see in Figure 6-3, this can be accomplished with one StackPane root node, one VBox branch (parent)<br />

node, and seven leaf (children) nodes (one TableView, two ImageView, and four Button UI controls). When you<br />

get into coding the Scene Graph next (finally!), you will use only 14 objects, and import only 12 classes, to make the<br />

entire top level for your InvinciBagel game, which you designed in the previous section, a reality. The TableView will<br />

overlay the ImageView composite, which contains the information screen layers of the design. This TableView object<br />

will be added in later stages of your game design. An ImageView backplate will contain the InvinciBagel artwork;<br />

an ImageView compositing layer will contain three different transparent images, which will seamlessly overlay the<br />

backplate image, based on the ActionEvents (clicks of the Button controls); and a VBox Parent UI layout container<br />

will contain the four Button controls. You will also create an Insets object to hold the padding values to fine-tune the<br />

button bank alignment.<br />

Figure 6-3. Primary splash screen Scene Graph node hierarchy, the objects it contains, and the assets it references<br />

Because a Button object cannot be positioned individually, I had to use the HBox class, along with an Insets class<br />

and a Pos class, to contain and position the Button controls. I will be going over the classes you will be using for this<br />

high-level design in this chapter so that you have an overview of every class that you are going to be adding to your<br />

InvinciBagel class to create this top-level UI design.<br />

The way I optimized the Scene Graph use for the four different screens needed to match the four different<br />

buttons was to use one ImageView as a backplate to contain the InvinciBagel splash screen artwork and then one<br />

more ImageView to contain different composite images (overlays) that use transparency (alpha channel). In this way,<br />

you can simulate four different screens, using only two ImageView Scene Graph Node objects.<br />

Finally, a TableView Scene Graph node will contain the table structure for the high scores table. This will<br />

be created via the score engine, which you will be creating last, after you finish your entire game design and<br />

programming. For now, you will leave the High Scores and Play Game button code unimplemented.<br />

126<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!