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

A PerspectiveCamera class has a fieldOfView attribute (state or property). This can be used to change
your viewing volume, just like a real camera zoom lens can, when you zoom it in from a wide angle to a
zoom. The default setting for the fieldOfView attribute is an acute angle of 30 degrees. If you remember your
geometry class from high school, you can visualize this field of view by looking down the y-axis (the up and
down one) at the camera. As you might expect, there are .getFieldOfView() and .setFieldOfView(double)
method calls to control this camera class attribute.
Next, let’s take a closer look at the Scene utility classes. After that, we will take a closer look at some of
the nine javafx.scene subpackages, such as javafx.scene.text, javafx.scene.image, javafx.scene.shape, and
javafx.scene.layout.


JavaFX Scene Utilities: Scene Snapshots and Anti-aliasing


Finally, we should take a quick look at the three utility classes that are shown on the right side of Figure 7-2,
as they can be used to increase the quality of your scene output on your user’s device screen (using anti-
aliasing), as well as to provide screen capture capabilities to either your user (for social media sharing) or
your gameplay logic.
Let’s get the SceneAntialiasing class out of the way first. You learned about anti-aliasing in Chapter 2 ,
and I showed you how it uses an algorithm to smooth jagged edges where two different colors come together,
usually on a diagonal line or circular area of an image composite. An image composite is where two separate
images are placed in layers to form one resulting image. Sometimes the edges that differ between the image
components that are in these two (or more) image layers will need to be smoothed. Smoothing (anti-aliasing)
is needed so a final image composite looks like it is one seamless image, which is the intention of the artist
or game designer. Interestingly, we are already implementing the JavaFX “layer engine” in our JavaFXGame
application using the StackPane class (panes are layers). The “layer stack” image compositing approach is
common in games as well as in software such as Photoshop or GIMP.
What the SceneAntialiasing class does is to provide anti-aliasing processing (algorithm) to 3D scenes
so that they can be composited over your scene’s 2D background, whether that is the default Color.WHITE
or any other color value, a 2D image (creating a hybrid 2D and 3D app), or anything else, like Digital
Video. The SceneAntiAliasing class allows you to set the static SceneAntialiasing data field to a value of
DISABLED (turns anti-aliasing off ) or BALANCED (turns anti-aliasing on). The balanced option provides a
balance of quality and performance, which simply means that more anti-aliasing quality will be processed
the more processing power that the device hardware brings to the table.
Next let’s take a look at the SnapshotParameters class (object), which is used to set up (contain) a
rendering attribute parameter that will be used by your SnapshotResult class (object). The parameters
include what type of Camera (parallel or perspective) object will be used, whether the depthBuffer used for
3D is on (true for 3D) or off (false for 2D), a Paint object used to contain a resulting snapshot image data, a
Transform object used to contain any transform data, and a Rectangle2D object that is used to define the
viewport area that is to be rendered. This would be the snapshot dimensions and what X,Y location on the
screen the upper-left corner of the SnapshotResult is set to.
This SnapshotResult class (and the object created using this class, more importantly) contains
your resulting snapshot image data, requested parameters, and source node in the Scene Graph that
it was generated from. For this reason, three methods supported by this class would be obvious: a
.getImage() method will get the snapshot image, a .getSource() method will get the source node, and a
.getSnapshotParameters() method will get the SnapshotParameters.


Scene Subpackages: Nine Scene-Related Packages


You might be thinking “Whew! That was a lot to cover in that javafx.scene package overview!” and indeed
the core javafx.scene package has a lot of classes in it covering scene creation, scene graph organization,
and scene utilities such as lighting, cameras, cursors, screenshots (“sceneshots”), and settings utilities.

Free download pdf