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 />

The LightBase class, and its PointLight and AmbientLight subclasses, can be used to light your scenes. These<br />

classes are primarily used for 3D scenes, and they require 3D capabilities on any platform that the game is running<br />

on, which is not really a problem these days, as most of the major CPU manufacturers also make (and include) GPUs.<br />

Also, it is important to note that the Prism game engine will simulate a 3D environment (GPU), using 3D processing<br />

emulation, if one is not available on the platform that is rendering the game. In addition, if you set it up correctly, you<br />

can use the lighting classes with your 2D games or use lighting with a hybrid 2D-3D game.<br />

The Camera class, and its ParallelCamera and PerspectiveCamera subclasses, can be used to photograph<br />

or video your scene in 3D and 2D (and hybrid) game applications. Two of the camera classes, Camera and<br />

ParallelCamera, do not require that 3D (GPU) capabilities be present on the platform that is playing your <strong>Java</strong>FX<br />

application (in this case, a game).<br />

The subclasses of the Camera class provide two different, specialized types of cameras. The ParallelCamera class<br />

can be used for rendering scenes without any depth perspective correction, which in the 3D industry is called an<br />

orthographic projection. What this means is that this class is perfect for use with 2D scenes (and for 2D games).<br />

The PerspectiveCamera class has a much more complex camera, used for 3D scenes, which will support 3D<br />

viewing volumes. Like the LightBase class and its subclasses, the PerspectiveCamera class requires 3D capabilities on<br />

the hardware platform that the application (or game) is running on.<br />

The PerspectiveCamera class has a fieldOfView attribute (state or variable), which can be used to change its<br />

viewing volume, just like a real camera zoom lens, when you zoom it in from wide angle. The default setting for<br />

the fieldOfView attribute is an acute angle of 30 degrees. If you remember your geometry from high school, you<br />

can visualize this field of view by looking down the y (vertical) axis at the camera. As you might expect, there are<br />

.getFieldOfView() and .setFieldOfView(double) method calls to control this camera class attribute.<br />

Next, let’s take a closer look at the Scene utility classes. After that, you will examine some of the javafx.scene<br />

subpackages, such as javafx.scene.text, javafx.scene.image, javafx.scene.shape, and javafx.scene.layout.<br />

<strong>Java</strong>FX Scene Utilities: Scene Snapshots and Antialiasing<br />

Finally, you should take a quick look at the three utility classes, shown in the right-hand column in Figure 4-2, as<br />

they can be used to improve the quality of scene output on the user’s device’s screen (using antialiasing) as well as to<br />

provide screen capture capabilities to either your user (for social media sharing) or your game play logic itself.<br />

Let’s investigate the SceneAntialiasing class first. Antialiasing is a digital imaging industry term that references<br />

an algorithm that smoothes jagged edges where two colors come together, usually on a diagonal line or in the<br />

circular area of an image composite. An image composite is two separate images placed in layers to form one<br />

image. Sometimes, the edges between the image components of these two (or more) image layers will need to be<br />

smoothed. Smoothing (antialiasing) is required so that a final composite looks like it is one seamless image, which<br />

is the intention of the artist or game designer. Interestingly, you are already implementing the <strong>Java</strong>FX “layer engine”<br />

in your InvinciBagel application, using the StackPane class (panes are layers). The “layer stack” image-compositing<br />

approach is common in games as well as in software, such as Photoshop and GIMP.<br />

The SceneAntialiasing class offers antialiasing processing (algorithm) to 3D scenes so that they can be<br />

composited over your 2D scene background, whether that is the default, Color.WHITE, or any other color value; a<br />

2D image (creating a hybrid 2D-3D application); or anything else, for that matter. The SceneAntialiasing class allows<br />

you to set the static SceneAntialiasing data field to a value of DISABLED (turn antialiasing off) or BALANCED (turn<br />

antialiasing on). The balanced option gives a balance of quality and performance, which simply means that the more<br />

processing power the device’s hardware brings to the table, the more antialiasing quality will be processed.<br />

Next, let’s explore the SnapshotParameters class (object), which is used to set up (contain) a rendering attribute<br />

parameter that will be used by the SnapshotResult class (object). The parameters include the type of Camera<br />

(parallel or perspective) object to be used; whether the depthBuffer (used for 3D) is on (true for 3D) or off (false for<br />

2D); a Paint object, used to contain the image data; a Transform object, used to contain any transform data; and a<br />

Rectangle2D object, used to define the viewport area to be rendered (i.e., the snapshot dimensions).<br />

You will be looking at all these javafx.scene subpackage classes and concepts in this chapter as well as using<br />

many of them over the course of this book. Much of the functionality that you will be tapping into for your <strong>Java</strong> 8 game<br />

development will be found in these <strong>Java</strong>FX 8.0 subpackages.<br />

www.it-ebooks.info<br />

81

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

Saved successfully!

Ooh no, something went wrong!