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 Point2D and Point3D classes (objects, ultimately) hold x, y coordinates for a 2D point on a 2D plane or x, y,<br />

z coordinates for a 3D point in 3D space. These Point objects will be used to build more complex 2D or 3D structures<br />

made up of a collection of points, such as a 2D path or a 3D mesh. The Point2D and Point3D constructor method calls<br />

are not overloaded, and they use the following standard formats, respectively:<br />

Point2D(double X, double Y)<br />

Point3D(double X, double Y, double Z)<br />

The Rectangle2D class (object) can be used to define a rectangular 2D area, often referred to as a plane, and has<br />

many uses in graphics programming, as you might well imagine. A Rectangle2D object has a starting point in the<br />

upper left-hand corner of the rectangle specified, using an x and a y coordinate location as well as a dimension<br />

(width by height). A constructor method for a Rectangle2D object has the following standard format and is not<br />

overloaded:<br />

Rectangle2D(double minX, double minY, double width, double height)<br />

In addition, a Dimension2D class (object) specifies only the width and height dimensions and does not place the<br />

dimensions (which would make it a rectangle) on the screen using an x, y location. This class’s constructor method<br />

is as follows:<br />

Dimension2D(double width, double height)<br />

The Insets class (object) is like a Dimension2D class, in that it does not provide a location value for the inset<br />

but does offer offsets for a rectangular inset area, based on top, bottom, left, and right offset distances. The Insets<br />

method is in fact overloaded, so you can specify an equidistant inset or a customized inset, using the following code:<br />

Insets(double topRightBottomLeft)<br />

Insets(double top, double right, double bottom, double left)<br />

The Bounds class is a public abstract class and will never be an object, but instead is a blueprint for creating<br />

Node boundary classes, such as its BoundingBox subclass. The Bounds superclass also allows a negative value,<br />

which is used to indicate that a bounding area is empty (think of it as null, or unused). A BoundingBox class uses<br />

the following (overloaded) constructor methods to create a 2D (first constructor) or 3D (second constructor)<br />

BoundingBox object:<br />

BoundingBox(double minX, double minY, double width, double height)<br />

BoundingBox(double minX, double minY, double minZ, double width, double height, double depth)<br />

Next, let’s take a look at Event and ActionEvent processing in <strong>Java</strong>FX, as this will add interactivity to your games.<br />

96<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!