Game Development Reference
In-Depth Information
Scene Graph Code: Optimizing Your Current Invin-
ciBagel Class
I know you are eager to work on the InvinciBagel class code, so let's clean up, organ-
ize, and optimize the existing Java code to implement this top-level UI screen design.
First, put the object declaration and naming Java code at the top of the InvinciBagel
class. This is more organized, and all the methods that are inside your class will be able
to see and reference these objects without using Java modifier keywords. As you can
see in
Figure 6-4
, these include your existing scene Scene object, root StackPane ob-
ject, and btn Button object (which I am renaming gameButton). I added three other
Button objects, named
helpButton
,
scoreButton
, and
legalButton
, all declared and
named using a single line of Java code, as well as two ImageView objects, named
splashScreenbackplate
and
splashScreenTextArea
. You also need to create four
Image objects to hold digital image assets, which will be displayed in the ImageView
nodes; I have named these
splashScreen
,
instructionLayer
,
legalLayer
, and
scoresLayer
and declared them, using one
compound
Java statement. Finally, you de-
clare and name the
buttonContainer
VBox object and the
buttonContainerPadding
Insets object. NetBeans will write import statements for you, so long as you use the
Alt+Enter keyboard shortcut, selecting the correct javafx package and class path. The
imports are shown at the top of the figure.