Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 9 ■ JavaFX 9 User InterFaCe DesIgn: the Front enD For Java 9 game DesIgn


You are by no means finished with this user interface design part of your pro Java 9 game development.
Be prepared to refine it even more later in the book, when we make it interactive (Chapter 10 ) and make it a
2D plane when we convert your now 2D Scene into a 3D Scene by adding a PerspectiveCamera to the Scene
root (Chapter 11 ), all of which will necessitate changes to the StackPane object compositing layer pipeline
attributes as well as to the coordinate referencing system. As I said, this book is going to get more and more
complex with each chapter, until your knowledge of Java 9 and JavaFX and NetBeans 9 is good enough to
create any i3D game design you can imagine!


Summary


In this ninth chapter, you added even more code to your JavaFXGame.java class by adding to the
compositing pipeline for your actual top-level user interface design for your game using the JavaFX
Image, ImageView, Background, BackgroundImage, Text, and TextFlow classes. The first thing that you did
was to finish the JavaFX Scene Graph hierarchy design, which I visualized in Figure 9-1, showing how the
SceneGraph uses one root Node object, three branch Node objects, and seven leaf Node objects (five Button
objects, one ImageView object, and one TextFlow object). Later, you will add more branch and leaf Node
objects for the 3D part of the game, primarily to hold 3D objects (primitives) offered by JavaFX or your own
3D mesh geometry. During the chapter you added a second ImageView node for logo compositing.
Next, you learned about some of the JavaFX classes that we were going to implement in these new
methods during this chapter as well as the next one. These included the Image class, as well as the
ImageView class, both from the javafx.scene.image package. You also looked at the Te xt and TextFlow
classes from the javafx.scene.text package.
You instantiated and configured these new compositing Node objects and then coded two new
methods to handle your Image and Text assets. Your loadImageAssets() method instantiated and
configured your digital imagery assets into Image objects, and a createTextAssets() method instantiated
and configured your text information assets into Text objects for later use with the TextFlow Node object in
your Scene Graph.
Then you made your Button widths uniform using a value of 125 pixels and subsequently learned
how to use the Background and BackgroundImage classes (objects) to be able to utilize the background
property of the StackPane as another compositing layer in your compositing pipeline without adding any
more Node objects to your JavaFX Scene Graph hierarchy. This reinforces my optimization approach for
pro Java games development of utilizing everything that each Node in your Scene Graph gives you so that
you can keep the total number of Nodes that are being traversed on each pulse event to an absolute bare
minimum.
In the next chapter, you are going to learn about event handling classes in JavaFX and implement
the Java code inside of your ActionEvent EventHandler program logic. You will also be learning how to
implement some cool special effects in the process, as some of these will be triggered by Java 9 statements,
inside of your event handlers. After that, we will be getting into 3D and the classes and assets you will need
to know about to enter the realm of 3D.

Free download pdf