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

Figure 6-14. Profiling the Scene Graph UI design thus far to make sure that it does not use any perceptible thread<br />

overhead<br />

<strong>Java</strong> 8 and its <strong>Java</strong>FX engine spawned nearly a dozen threads, so your game application is already highly<br />

multithreaded, and it does not even need to be at this point in time! The teams at Oracle are working diligently at<br />

making <strong>Java</strong>FX the premier game engine, so the performance just keeps getting better and better, which is great news<br />

for <strong>Java</strong> 8 game developers!<br />

Summary<br />

In this sixth chapter, you got your hands dirty doing the actual top-level UI design for your game as well as outlining<br />

the underlying game engine component design and figuring out the most efficient Scene Graph node design. Then,<br />

you got back into <strong>Java</strong> 8 game programming and redesigned your existing bootstrap <strong>Java</strong> 8 code, originally created by<br />

NetBeans 8.0.<br />

Because this NetBeans-generated <strong>Java</strong> code design was not optimal for your purposes, you rewrote it completely<br />

to make it more organized. You did this by creating two custom <strong>Java</strong> methods,.createSplashScreenNodes() and<br />

.addNodesToStackPane(), to modularize the Scene Graph node creation process as well as the adding of the three<br />

Parent (and leaf) Node objects to the Scene Graph root (in this case, the StackPane object, which you are using for its<br />

multilayer UI object-compositing capability).<br />

Next, you learned about some of the <strong>Java</strong>FX classes for implementing these new methods, including the Pos class<br />

and the Insets class, from the javafx.geometry package; the Image and the ImageView class, from the javafx.scene.<br />

image package; the HBox class, from the javafx.scene.layout package; and the TableView class, from the javafx.<br />

scene.control package. You coded the new .createSplashScreenNodes() method, which instantiated and configured<br />

the HBox object, using the Insets object, and then the Image and ImageView objects and the four Button objects.<br />

Once all these Scene Graph nodes were instantiated and configured, you wrote an .addNodesToStackPane() method<br />

to add Node objects to the StackPane root object so that they would be displayed by the Stage object, which references<br />

the Scene Graph’s root object. Next, you tested your top-level game application UI design. Then, you added in the last<br />

couple of Image objects and added ActionEvent EventHandler program logic. Finally, you profiled the application to<br />

make sure it was efficient.<br />

In the next chapter, I will present the <strong>Java</strong>FX pulse engine and the AnimationTimer class so that you can create<br />

the infrastructure for your <strong>Java</strong> 8 game engine, which will process your game events in real time.<br />

144<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!