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


to have any children (child object), so they inherently have to be at the end of the tree and branches by the
nature of their class function design.
A leaf node will therefore always contain a JavaFX class that has not been subclassed (extended)
from the Parent class or from the Group, Region or SubScene class and that has not itself been specifically
designed to have any child elements (child objects) within it (or below it) within your JavaFX Scene Graph
hierarchy.
The three subclasses of the Parent class can be utilized as branch nodes. These include the Group class
for grouping child (leaf node) objects so that opacity, transforms, and special effects can be applied to Group
nodes all at once; the Region class for grouping child (leaf node) objects in 2D to form screen layouts, which
could be styled using CSS3, if you like; and the WebView class, which is used to manage the WebEngine
class, which renders HTML5, JS, and CSS content in a WebView.


JavaFX Scene Content: Lights, Camera, Cursor, Action!


Next, let’s take a look at the eight classes listed in the center of Figure 7-2 that provide some powerful
multimedia tools for controlling your application’s cursor, as well as providing custom lighting special
effects and custom camera capabilities to your 2D and 3D JavaFX applications. In this case that would be
games, but it could also be e-books or iTV shows or anything for IoT that requires the powerful new media
capabilities that JavaFX provides for the Java 9 APIs.
The more generalized classes (Cursor, LightBase, Camera) that are listed in the center portion of
Figure 7-2 are parent classes, and the more specialized ones (ImageCursor, PointLight, ParallelCamera,
etc.) listed after each of those are the subclasses of those parent classes. Except for the LightBase class, that
seems to be stating the obvious!
As you might have guessed (correctly), the JavaFX Cursor class can be used to control the application
cursor graphic (arrow, hand, closed hand, open hand, resize, move, text, wait, none) being used at any given
time. The ImageCursor subclass can be used to define and supply a custom image-based cursor, using an
X and Y location within a custom cursor image that will define where its “click point,” also known as the
cursor’s “hotspot,” is located.
The LightBase class, and its PointLight and AmbientLight subclasses, can be used to light your scenes.
These classes are primarily used for 3D scenes, and they require 3D capabilities on any platform that the
game is running on, which is not really a problem these days as most of the major CPU manufacturers
also make (and include) GPUs. Also, it is important to note, the Prism game engine will simulate the 3D
environment (GPU) using 3D processing emulation if a GPU is not available on the hardware platform that is
rendering your game. This is termed software rendering.
If you set it up correctly, you could also use these lighting classes with your 2D games, or use lighting
with a “hybrid” 2D and 3D game, which we will be taking a look at later during this book as well, since
JavaFX supports it.
The Camera class, and its ParallelCamera and PerspectiveCamera subclasses, can be used to
photograph or video your scene and can be used in 3D, 2D, and hybrid game applications. Two of the
camera classes, Camera and ParallelCamera, do not require that 3D (GPU) capabilities be present on the
platform that is playing your JavaFX application, in this case, a game. A Parallel Camera view is sometimes
called Orthographic Projection in 3D software.
The subclasses of the Camera class provide two different specialized types of Cameras. The
ParallelCamera class can be utilized for rendering scenes without any depth perspective correction, which in
the 3D industry is called an orthographic projection. This means this class is perfect for use with 2D scenes
(and for 2D games).
The PerspectiveCamera class provides a far more complex camera used for 3D scenes, which will
support 3D viewing volumes. Like the LightBase class, and its subclasses, a PerspectiveCamera class will
require 3D capabilities for the hardware platform that your pro Java 9 game (or IoT application) will be
running on (called the target platform).

Free download pdf