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

Prism bridges the powerful 3D game engines (DirectX, OpenGL) that are on the major OS platforms as well as on<br />

consumer electronics (embedded) devices so <strong>Java</strong>FX 8.0 can offload complex rendering task processing to graphics<br />

processing unit (GPU) hardware from NVIDIA (GeForce), AMD (ATI Radeon), and Intel. This makes <strong>Java</strong>FX (and thus<br />

<strong>Java</strong> 8) games faster and allows games to use less CPU processing power for rendering game assets to the screen. This<br />

in turn allows more CPU processing power be used for game play logic, such as AI and collision detection. You will be<br />

learning about these areas of game design after you master the <strong>Java</strong>FX engine in this fourth chapter of the book.<br />

It is important to note that game developers do not need to understand the inner workings of the Quantum<br />

(threading), Glass (windowing), or Prism (rendering) engines to be able to take advantage of their amazingly powerful<br />

features. Throughout the book, you are going to be focusing on the top level (Scene Graph and Scene Builder) as<br />

well as the <strong>Java</strong>FX and <strong>Java</strong> 8 API levels of the diagram. I will also be covering the NetBeans IDE 8.0 level, which you<br />

learned about in Chapter 2 but which you will also be exploring much further during the remainder of this book.<br />

As for the lower levels of the diagram, NetBeans 8.0 will generate a <strong>Java</strong> bytecode file that is read by the custom<br />

JVM for each of the OS platforms. The JVM, illustrated at the bottom of the figure, can be installed for any given OS<br />

platform by downloading a <strong>Java</strong> 8 JRE, which you already encountered in Chapter 1, when you installed it as part<br />

of <strong>Java</strong> JDK 8.<br />

This JVM layer lets your game be installed as an application across all popular OS platforms as well as on<br />

embedded devices, which are also moving to support <strong>Java</strong>FX 8. Furthermore, you can generate your <strong>Java</strong> 8 game as a<br />

<strong>Java</strong> applet, which can be embedded in a web site, and there is even a deployment model, in which the application<br />

can be dragged out of the web site and onto your desktop, where it is installed as a full-fledged <strong>Java</strong> 8 application.<br />

In addition, there is already a way to run <strong>Java</strong>FX 8 applications on iOS 8, and Android 4.4 and 5.0. If you are<br />

interested in the latest information on this, simply google “<strong>Java</strong>FX on Android,” or “<strong>Java</strong>FX on iOS,”; you can bet that<br />

by 2015, Android 5.0 and Chrome OS devices will be running <strong>Java</strong>FX applications “natively,” meaning that you will<br />

someday (soon) be able to export <strong>Java</strong> (and <strong>Java</strong>FX engine) applications directly to Android 5.0, using IntelliJ, or to<br />

Chrome OS, using NetBeans 8.0. You should eventually be able to “code once, run everywhere” with this <strong>Java</strong> 8 and<br />

<strong>Java</strong>FX 8.0 dynamic duo! Oracle recently released <strong>Java</strong> 8 SE Embedded, <strong>Java</strong> 8 ME and <strong>Java</strong> 8 ME Embedded versions,<br />

all of which support <strong>Java</strong>FX.<br />

■ ■Note The JetBrains IntelliJ IDEA is now the official IDE used for creating 64-bit Android 5.0 applications. This<br />

IDE is examined in my Android Apps for Absolute Beginners, 3rd Edition (Apress, 2014), which covers developing 32-bit<br />

Android 4.0 applications, using an Eclipse IDE and <strong>Java</strong> 6, and 64-bit Android 5.0 applications, using an IntelliJ IDEA<br />

and <strong>Java</strong> 7.<br />

Let’s start at the top of the diagram, and take a look at the <strong>Java</strong>FX Scene Graph and the javafx.scene package,<br />

which implements Scene Graph in the <strong>Java</strong>FX API (you will look at Scene Builder in the next chapter).<br />

<strong>Java</strong>FX Scene Package: 16 Core <strong>Java</strong> 8 Classes<br />

The first thing I want to do after our high-level overview is present one of the most important <strong>Java</strong>FX packages, the<br />

javafx.scene package. In Chapters 2 and 3, you discovered that there is more than one <strong>Java</strong>FX package. As you saw<br />

in Chapter 3 (see Figure 3-1), the InvinciBagel game application uses four different <strong>Java</strong>FX packages. The javafx.<br />

scene package contains 16 powerful <strong>Java</strong> 8 classes (remember, <strong>Java</strong>FX was recoded in <strong>Java</strong> 8), including the Camera,<br />

ParallelCamera and PerspectiveCamera, Cursor and ImageCursor, LightBase, PointLight, and AmbientLight<br />

classes; the Scene Graph classes (Node, Parent, Group, and SubScene); and some utility classes (see Figure 4-2).<br />

77

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

Saved successfully!

Ooh no, something went wrong!