Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 7 ■ IntroduCtIon to JavaFX 9: overvIew oF the JavaFX new MedIa engIne

The javafx.scene.input subpackage contains classes that are used to get input from the JavaFX app’s user,
including mouse and keyboard input, gestures, touchscreen, scrolling, zooming or swipes input, and clipboard
content, among other types of input. Input and actions are processed using the event-handling capabilities,
which you will be looking at in great detail during this book and which you have already experienced in your
Pro JavaFX 9 application, as seen in your bootstrap Java 9 code in lines 20 through 25 (shown in Figure 6-7).
The javafx.scene.layout subpackage contains classes that are used to create user interface design
layouts and can be used for your screen layout designs as well. These layout classes include classes that
control and manage backgrounds, add and style borders, and provide UI Pane management classes such as
StackPane, GridPane, TilePane, FlowPane, and AnchorPane. These Pane subclasses provide automatic
screen layout algorithms for UI controls in JavaFX. The Background class provides screen background
utilities, and the Border class provides screen border utilities, which can be used for spicing up graphics for
your user interface screens.
The javafx.scene.paint subpackage contains a Stop class; a Paint superclass and Color, ImagePattern,
LinearGradient, and RadialGradient subclasses; and the 3D Material superclass and its PhongMaterial
subclass. Those of you who are familiar with 3D content production will recognize this Phong shader
algorithm, which will allow different surface looks (plastic, rubber, etc.) to be simulated. These Material and
PhongMaterial classes need the i3D capabilities to be present on the playback hardware in order to function
successfully, just like the SceneAntialiasing, PerspectiveCamera, and LightBase classes and subclasses.
These need GPU hardware acceleration or software rendering.
The abstract Paint class creates subclasses that paint objects, the Color class colors these objects (fills
them with color), LinearGradient and RadialGradient are Paint subclasses that fill objects with color
gradients, and the Stop class allows you to define where a gradient color starts and stops inside of the
gradient, which is where its name comes from. Finally, there is your ImagePattern class, which can fill a
Shape object with a tileable image pattern, which can be quite useful for games.
The javafx.scene.shape subpackage contains classes for 2D geometry, commonly called shapes,
as well as for 3D geometry, commonly called meshes. A Mesh superclass and its TriangleMesh subclass
handle 3D geometry, as do the Shape3D superclass and its Box, Sphere, Cylinder, and MeshView
subclasses. The Shape superclass has a lot more subclasses (12); these are 2D geometry elements, and they
include the Arc, Circle, CubicCurve, QuadCurve, Ellipse, Line, Path, Polygon, Polyline, Rectangle, and
SVGPath classes. There is also “path” support, which a path being defined as an “open” shape (I like to call
it a “spline” since I am a 3D modeler) provided by the PathElement superclass, and its ArcTo, ClosePath,
CubicCurveTo, HLineTo, LineTo, Mo v e To, QuadCurveTo, and VLineTo subclasses, which allow you to
draw spline curves to create your own custom Scalable Vector Graphics (SVG) shapes.
The javafx.scene.text subpackage contains classes for rendering text shapes and fonts into your scenes.
This includes the Font class for using any fonts that you may want to use that are not the JavaFX “system”
font, as well as the Te xt class for creating a Text Node that will display the text values using this font. There’s
also a specialized layout container class called TextFlow, which is used to “flow” text, much like you would
see done in a word processor.
The javafx.scene.transform subpackage contains classes for rendering 2D and 3D spatial
transformations, such as the Scale, Rotate, Shear, Translate, and Affine (3D rotation) subclasses of the
Transform superclass. These can be applied to any Node object in the Scene Graph. This allows anything
in your Scene Graph (text, UI controls, shapes, meshes, images, media, etc.) to be transformed in any way
that you like, which affords JavaFX game developers a ton of creative power when it comes to transforming
things. Translation, in case you are wondering, is a linear movement of an entire object. Shear is linear
movement on a 2D plane in two different directions or movement in one direction when another part of the
2D plane is fixed. Imagine moving the top of a plane, while the bottom remains fixed, so the square becomes
a parallelogram, or moving the top and bottom of the same plane (a square) in different directions.
Now that we have looked at a plethora of important and useful classes (objects) in the javafx.scene
package and its related subpackages, let’s take a look at the other 18 top-level JavaFX packages to get an idea
of the other key capabilities that JavaFX offers for application development, and of course we will focus on
those that can be utilized for game development as we have been doing so far during this chapter and will
continue to do throughout the book.

Free download pdf