28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Let’s start with the packages that have the fewest classes. The table lists subpackages alphabetically, but the<br />

first one, javafx.scene.canvas, coincidentally contains only one class, the Canvas class, which, as its name suggests,<br />

is employed to create a Canvas object that is used as a canvas for you to create things with! The next subpackage<br />

listed is javafx.scene.chart; this has charting classes, such as PieChart, LineChart, XYChart, BarChart, AreaChart, and<br />

BubbleChart, for use in business applications, which is a different book entirely, so I will not be covering charting.<br />

The next subpackage, javafx.scene.control, offers all the UI control (“widget,” in Android) classes, such as<br />

Button, Menu, CheckBox, RadioButton, DatePicker, ColorPicker, ProgressBar, Slider, Label, Scrollbar, and TextField<br />

and about eight dozen others. Because there are approximately a hundred classes in javafx.scene.control, I am not<br />

even going to attempt to cover it here; an entire book could probably be written about this subpackage! If you want<br />

to review these classes, simply reference “javafx.scene.control” on Google or on the Oracle <strong>Java</strong> website, and you can<br />

peruse what these classes can do for days on end. For this subpackage, “reference” is the key word, as you will want to<br />

reference this package and its classes individually at the time you need to implement a given UI element.<br />

The next subpackage, javafx.scene.effect, provides all the special effects classes, almost two dozen of them.<br />

These can be very useful for <strong>Java</strong> 8 game development, so this is one of the few subpackages that I am going to cover in<br />

detail in this section.<br />

The javafx.scene.image subpackage is used to implement digital imagery within <strong>Java</strong>FX, and it has the Image,<br />

ImageView, WritableImage, PixelFormat, and WritablePixelFormat classes. The ImageView class is what you will<br />

normally use to hold your digital image assets, and the more advanced PixelFormat classes let you create digital<br />

imagery on a pixel-by-pixel basis if you want to do more advanced (algorithmic) pixel-based digital image creation.<br />

The javafx.scene.input subpackage includes classes that are used to get input from the <strong>Java</strong>FX application’s user.<br />

This input is processed using the event handling capabilities, which you will be examining in great detail over the course<br />

of this book and which you have already experienced in your <strong>Java</strong>FX application, in Chapter 3 (see Figure 3-2, ll. 22 to 24).<br />

The javafx.scene.layout subpackage contains classes that are used to create UI design layouts and that<br />

can be used for your screen layout designs as well. These layout classes include classes that control and manage<br />

backgrounds; add and style borders; and provide UI pane management, such as StackPane, TilePane, GridPane,<br />

FlowPane, and AnchorPane. These UI classes offer automatic screen layout algorithms for the UI controls in<br />

<strong>Java</strong>FX. The Background class (and subclasses) furnishes screen background utilities, and the Border class (and its<br />

subclasses) supplies screen border utilities, which can be used for spicing up the graphics design for your UI screens.<br />

The javafx.scene.media subpackage holds classes that are used for the playback of audio or video media,<br />

including the Media, MediaPlayer, and MediaView classes. The Media class (or object, actually) references and<br />

contains the media (audio or video) asset, MediaPlayer plays that asset, and MediaView (in the case of video) displays<br />

the asset. This subpackage also has a Track superclass and AudioTrack, VideoTrack, and SubtitleTrack subclasses<br />

as well as the AudioClip, AudioEqualizer, and EquilizerBand classes, which provide advanced audio (equalizer)<br />

controls and short-form audio clips, or snippets of audio that are perfect for use in games. You will be using the<br />

AudioClip class later in the book (see Chapter 15).<br />

The javafx.scene.paint subpackage contains a Stop class and the Paint superclass and its Color, ImagePattern,<br />

LinearGradient, and RadialGradient subclasses as well as the Material superclass and its PhongMaterial subclass.<br />

Those of you who are familiar with 3D content production will recognize this Phong shader algorithm, which will<br />

allow different surface looks (plastic, rubber, and so on) to be simulated. The Material and PhongMaterial classes<br />

need 3D capabilities to be present on the playback hardware to function successfully, just like the SceneAntialiasing,<br />

PerspectiveCamera, and LightBase class (and subclasses). The Paint class creates your Paint object, the Color class<br />

colors this object (fills it with a color), the LinearGradient and RadialGradient classes fill the Paint object with color<br />

gradients, and the Stop class lets you define where gradient colors start and stop inside the gradients. Finally, there is<br />

an ImagePattern class, which can fill a Paint object with a tileable image pattern (this can be quite useful for games).<br />

The javafx.scene.shape subpackage provides classes for 2D geometry (commonly referred to as shapes) as well<br />

as for 3D geometry (commonly referred to as meshes). A Mesh superclass and its TriangleMesh subclass handle<br />

3D geometry, as do the Shape3D superclass and its Box, Sphere, Cylinder, and MeshView subclasses. The Shape<br />

superclass has many more subclasses (11); these are 2D geometry elements and include the Arc, Circle, CubicCurve,<br />

Ellipse, Line, Path, Polygon, Polyline, QuadCurve, Rectangle, and SVGPath classes. A path support, a path being<br />

defined as an open shape (I like to call it a spline, as I am a 3D modeler), is also supplied by the PathElement<br />

superclass and its ArcTo, ClosePath, CubicCurveTo, HLineTo, LineTo, MoveTo, QuadCurveTo, and VLineTo<br />

subclasses, which allows you to draw spline curves to create your own custom shapes!<br />

www.it-ebooks.info<br />

83

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

Saved successfully!

Ooh no, something went wrong!