28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4 ■ An Introduction to <strong>Java</strong>FX 8: Exploring the Capabilities of the <strong>Java</strong> 8 Multimedia Engine<br />

Figure 4-3. <strong>Java</strong>FX Scene Graph hierarchy, starting with the root node and progressing to branch and leaf nodes<br />

The root node is the topmost node, which is why it is called the root, even though it is at the top, not the bottom,<br />

like a root would be in the plant world. A root node has no parent, that is, nothing above it in the Scene Graph<br />

hierarchy. A root node is itself a parent to the branch nodes and leaf nodes below it.<br />

The next most powerful (and complex) construct in the Scene Graph tree is the branch node, which uses the<br />

javafx.scene.Parent class as its superclass and which can contain children (this is logical, as it extends a class aptly<br />

named Parent). A branch node can contain other branch nodes, as well as leaf nodes, so it can be used to create some<br />

very complicated and powerful Scene Graph hierarchy (or Scene Graph architecture) constructs.<br />

The last level in the hierarchy is the leaf node. A leaf node is the end of the branch and, as such, cannot have<br />

children. It is important to note that leaf nodes can come directly off the root node, as you can see in Figure 4-3.<br />

Branch nodes can be created by using the Parent, Group, or SubScene classes (see Figure 4-2) or any of their<br />

subclasses, such as the WebView, PopupControl, Region, Pane, or StackPane class.<br />

Examples of leaf nodes include <strong>Java</strong>FX classes (as objects), which can be configured using parameters, such as<br />

shapes, text, or an ImageView, but which are design or content components, in and of themselves, and have not been<br />

designed to have children (child objects).<br />

A leaf node will therefore always contain a <strong>Java</strong>FX class that has not been subclassed (extended) from the Parent<br />

class, and that has not itself been specifically designed to have child elements (child objects) within it, or below it, in<br />

the <strong>Java</strong>FX Scene Graph hierarchy.<br />

The four subclasses of the Parent class can all be used as branch nodes and include the Group class, for grouping<br />

child (leaf node) objects, so that opacity, transforms, and effects can be applied to them; the Region class, for<br />

grouping child (leaf node) objects to form screen layouts, which can also be styled using CSS; the Control class, which<br />

can be used to create custom user interface elements (called controls in <strong>Java</strong>FX); and the WebView class, which is<br />

used to contain the <strong>Java</strong>FX WebEngine class (this class renders HTML5 and CSS3 content into a WebView).<br />

<strong>Java</strong>FX Scene Content: Lights, Camera, Cursor, Action!<br />

Next, let’s take a look at the eight classes listed in the center column in Figure 4-2. They provide powerful multimedia<br />

tools for controlling your application’s cursor as well as custom lighting special effects and custom camera capabilities<br />

for your 2D and 3D <strong>Java</strong>FX applications (in this case, games, but they could also be e-books, or iTV shows, or anything<br />

else that requires the powerful new media capabilities that <strong>Java</strong>FX offers via the <strong>Java</strong> language).<br />

The more generalized classes (Cursor, LightBase, Camera) in the figure are parent classes, and the more<br />

specialized ones (ImageCursor, PointLight, ParallelCamera, and so on) listed after each of those are the subclasses<br />

of those parent classes. Except the LightBase class, that seems to be stating the obvious!<br />

As you may have guessed (correctly), the <strong>Java</strong>FX Cursor class can be used to control the application cursor<br />

graphic (arrow, hand, closed hand, crosshair, and so on) being used at any given time. The ImageCursor subclass can<br />

be used to define and supply a custom image-based cursor as well as an x and a y location within the custom cursor<br />

image that defines where its point (also called the cursor hot spot) is located.<br />

80<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!