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

Figure 4-7. Run the project to look at the transparent Stage object; something is still set to White<br />

Because you are using a StackPane object to implement layers in the InvinciBagel application, this is the next<br />

level up that you need to try to set a transparency value for. Evidently, <strong>Java</strong>FX uses a Color.WHITE default background<br />

color value for all its objects. If I were on the <strong>Java</strong>FX design team, I would be arguing for this to be changed to the<br />

Color.TRANSPARENT constant, but, of course, this might confuse new users, as alpha channel and compositing layers<br />

are advanced concepts.<br />

The javafx.scene.layout.StackPane class is subclassed from the javafx.scene.layout.Region class, which has a<br />

.setBackground() method for setting the Background (class or object) value. Again, a TRANSPARENT value constant<br />

must be available, as you always need to set background values as transparent, especially for <strong>Java</strong> 8 game design.<br />

Interestingly, things are not always as straightforward and consistent as you would want them to be in <strong>Java</strong><br />

programming, as, to achieve exactly the same end result (installing a transparent background color/image plate<br />

for the design element), you have used thus far three different method calls, passing three custom object types:<br />

.initStyle(StageStyle object), .setFill(Color object), and .setBackground(Background object).<br />

www.it-ebooks.info<br />

93

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

Saved successfully!

Ooh no, something went wrong!