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 6 ■ The Foundation of Game Design: The <strong>Java</strong>FX Scene Graph and the InvinciBagel Game Infrastructure<br />

The <strong>Java</strong> class extension hierarchy for the Pos class starts at the java.lang.Object masterclass and progresses to the<br />

java.lang.Enum class, finally ending with the javafx.geometry.Pos class. As Figure 6-4 demonstrates (l. 6), Pos<br />

is in the <strong>Java</strong>FX geometry package and uses the following subclass hierarchy structure:<br />

java.lang.Object<br />

> java.lang.Enum<br />

> javafx.geometry.Pos<br />

The Pos class has a set of constants for providing a generalized horizontal and vertical positioning and alignment<br />

(see Table 6-1). As you will see in the next section, you will have to use an Insets class and object to obtain the<br />

pixel-accurate positioning that you desire. You will employ the BOTTOM_LEFT constant to position the Button<br />

control bank in the bottom-left corner of the splash screen.<br />

Table 6-1. Pos Class Enum Constants That Can Be Used for Positioning and Alignment in <strong>Java</strong>FX<br />

Pos Constant<br />

BASELINE_CENTER<br />

BASELINE_LEFT<br />

BASELINE_RIGHT<br />

BOTTOM_CENTER<br />

BOTTOM_LEFT<br />

BOTTOM_RIGHT<br />

CENTER<br />

CENTER_LEFT<br />

CENTER_RIGHT<br />

TOP_CENTER<br />

TOP_LEFT<br />

TOP_RIGHT<br />

Positioning Result (Object)<br />

On the baseline, vertically; at the center, horizontally<br />

On the baseline, vertically; on the left, horizontally<br />

On the baseline, vertically; on the right, horizontally<br />

On the bottom, vertically; at the center, horizontally<br />

On the bottom, vertically; on the left, horizontally<br />

On the bottom, vertically; on the right, horizontally<br />

At the center, vertically and horizontally<br />

At the center, vertically; on the left, horizontally<br />

At the center, vertically; on the right, horizontally<br />

At the top, vertically; at the center, horizontally<br />

At the top, vertically; on the left, horizontally<br />

At the top, vertically; on the right, horizontally<br />

Because the Pos class offers generalized positioning, it should be used in conjunction with the Insets class to<br />

effect pixel-precise positioning. Let’s take a look at the Insets class next, as it is also in the javafx.geometry package.<br />

The <strong>Java</strong>FX Insets Class: Providing Padding Values for Your UI<br />

The Insets class is a public class that directly extends the java.lang.Object masterclass, meaning that the Insets class<br />

was coded from scratch to provide insets, or offsets inside a rectangular area. Imagine a picture frame in which you<br />

place a mat, or an attractive border between the frame on the outside and the picture on the inside. This is what<br />

the Insets class does with two constructor methods: one provides equal, or even, insets, and the other, unequal, or<br />

uneven, insets.<br />

130<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!