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

VBox is sized above its specified width, the child objects use their preferred width values, and the extra space
will go unutilized. The default setting of fillWidth is true, and the children widths will be resized to fit the
VBox width. It is important to note that the VBox UI layout engine will lay out the managed child elements
regardless of their visibility attribute (also called a property, characteristic, or object variable) setting.
You will also notice that the classes we are adding during this chapter have inherently transparent or
empty backgrounds (I call them backplates), so we don’t have to do any extra work like we did in Chapter 7
to maintain alpha.
Now that we have taken several pages to discuss some of the classes from the javafx.scene.layout and
javafx.geometry packages, which you are using to create your UI (bank of Button objects) Design, let’s take
a close look at the SceneGraph grouping-related classes from the javafx.scene package. These classes will
allow us to implement the high-level SceneGraph hierarchy that you will need to put into place next to the
five JavaFX Button Control UI elements (objects) held inside your VBox UI layout container object, which is
inside of your StackPane UI layer compositing object. This Group (Node) container object will hold your i3D
game object hierarchy when we get into 3D and i3D later during this book.


JavaFX Group Class: High-Level Scene Graph Node Grouping


The Group class is a public class that directly extends the javafx.scene.Parent superclass, which extends the
javafx.scene.Node class, which extends the java.lang.Object master class. The Group object is therefore a
type of Parent (branch) Node object in the JavaFX Scene Graph, which is used for grouping other branch and
leaf node objects. The Group class uses the following Java class inheritance hierarchy structure:


java.lang.Object



javafx.scene.Node
javafx.scene.Parent
javafx.scene.Group



The Group Parent Node object contains an ObservableList of children Node objects, which will be
rendered in a predetermined order whenever this Group Parent Node object is rendered. A Group Node
object will take on the collective (summary) bounds of its children; however, it is not directly resizable. Any
transform, effect, or state applied to a Group will be applied to (passed through to) all of the children of that
Group Node but not to the Group itself.
This means that these applied transforms and effects will not be included in the Group Parent Node’s
layout bounds; however, if transforms and effects are set directly on the child Node objects inside of this
Group, those will be included in this Group’s layout bounds. So, to affect a Group Parent Node’s layout
bounds, you will do it from the inside out by transforming the members of the Group ObservableList, rather
than by transforming the Group object itself.
By default a Group Parent Node will automatically scale its managed child objects set to be resizable to
their preferred sizes during the layout pass. This ensures the Region or Control child objects will be scaled
properly as their state changes. If an application needs to disable this autosizing behavior, then it should
set autoSizeChildren to false. It is important to note that if the preferred size attribute of any of the child
objects is changed, they won’t be resized automatically because autoSizeChildren has been set to false.
This Group() constructor will create an empty group.


Group()


The overloaded Group(Collection) constructor method will construct a Group consisting of
a Java Collection containing a given Java collection of Node object children, using the following
constructor method:


Group(Collection children)

Free download pdf