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


Next, it’s time to test the code that reorganizes the JavaFXGame class and creates your UI design
structure and Scene Graph hierarchy for your game application. Let’s make sure all these UI Button elements
(objects) function.


Testing Your BoardGame: Process the Scene Graph


Click the green Play arrow shown at the top of the NetBeans 9 IDE circled in red in Figure 8-16 and Run your
JavaFXGame project. This will bring up the VBox UI layout container that is shown encircled in red on the
top-middle part of Figure 8-16. As you can see, you are getting a professional result, with no crashes, using
around a dozen-and-a-half import statements (external classes), a few dozen lines of Java code, and less
than a dozen child Nodes underneath your Scene Graph root Group Node object. It is important to optimize
your Scene Graph hierarchy because each pulse event that JavaFX will use to process your game design
structure will have to traverse this hierarchy, so the more compact it is, the better your game will perform,
and the smoother your user experience will be. Therefore, you should optimize everything from the get-go.
As you can see circled in red in the Output-JavaFXGame tab at the bottom of Figure 8-17, I have tested the
event-handling structures attached to all Button UI Control objects.


Figure 8-16. Click the Run (Play) icon at the top of NetBeans and test your code to make sure your UI design is
working

Free download pdf