Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 8 ■ JavaFX 9 SCene Graph hierarChy: a Foundation For Java 9 Game deSiGn


manage the characteristics for individual Actors that have been instantiated for your JavaFXGame game.
You will modify the existing JavaFXGame.java class to implement a UI, with Button controls accessing
functional information screens needed to provide the top-level user interface gameplay information
features. You’ll learn about several new JavaFX classes used for organization and positioning, including the
Group, VBox, Insets, and Pos classes.


Game Design Foundation: Primary Function Screens


One of the first things you will want to design for your game is the top-level, or highest-level, user interface
screens with which your game’s users will interface. This defines the user experience when the user
first opens your game. These screens will be accessed using your JavaFXGame Splash (Branding) Screen,
contained in the primary JavaFXGame.java class code. As you have seen already, this Java code will extend
the javafx.application.Application class and will launch the application, displaying a splash screen,
along with options to review the instructions, play the game, see the high scores, or review the game legal
disclaimers and game creator credits (programmer, artist, writer, composer, sound designer, etc.). Figure 8-1
shows a high-level diagram of the game starting with functional UI screens at the top and progressing down
to the JavaFXGame.java code and then to the APIs, to the JVM, and to the OS level.


This will require you to add four more Button nodes to the StackPane layout container Parent branch
node and eventually (in Chapter 9 ) an ImageView node to serve as a SplashScreen image container. This
ImageView node will have to be added to the StackPane “backplate” in order to be the first child node in the
StackPane (z-order=0), as the ImageView holds what I term the background plate for your Splashscreen UI
design. Since it is in the background, the image needs to be behind Button UI Control Node (SceneGraph)
elements, which will have z-order values of 1 to 5.
This means that initially you’ll be using only eight JavaFX SceneGraph Node objects: one Parent root
Group Node, a second StackPane layout “branch” Node, and five “leaf ” Button Control Nodes in a VBox UI
container Node to create your JavaFXGame (functional) info screens. Your instructions, legal disclaimers, and
credit screens will utilize a TextFlow and ImageView Node, so we’ll be at ten Node objects after Chapter 9.
You can use the VBox Node to contain UI Buttons, which we will be doing during this chapter to put game UI
navigation infrastructure in your game application. This is before we even consider adding a Group “branch”
Node, and branch and leaf Node objects under that, to contain the 3D gameplay screen. This is, of course,
where you want to get the best pulse update performance for your Java game.


Figure 8-1. JavaFXGame functional screens and how they’ll be implemented in Java 9 and JavaFX 9 by using
the JVM

Free download pdf