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 9 ■ Controlling Your Action Figure: Implementing <strong>Java</strong> Event Handlers and Using Lambda Expressions<br />

Figure 9-8. Showing the License Agreement dialog (left) and the download and update progress bar (right) in NetBeans<br />

Select the “I accept the terms in all of the license agreements” checkbox, and click on the Update button, to start<br />

the downloading and installation process. As you can see on the bottom-right of Figure 9-8, a progress bar will tell you<br />

exactly how much has been downloaded, as well as what is being downloaded and installed onto the system.<br />

Let’s spend the remainder of this chapter taking a look at event handling, and the event-related classes in <strong>Java</strong><br />

and <strong>Java</strong>FX that we can use to provide different types of event handling to our <strong>Java</strong> 8 game development efforts.<br />

Event Handling: Adding Interactivity to Your <strong>Games</strong><br />

One could argue that event handing is at the very foundation and core of game development, as without a way to<br />

interface with the game play logic and actors, you really don’t have much of a game at all. I am going to cover the <strong>Java</strong><br />

and <strong>Java</strong>FX event handling related classes during this section of the chapter, and then we’ll implement keypad event<br />

handing, so that we can support using the arrow keys to navigate our InvinciBagel character around the screen. After<br />

that, we’ll turn that <strong>Java</strong> 7 compatible code into <strong>Java</strong> 8 compatible lambda expressions, and then we will be ready to<br />

cover sprite movement around the screen during the next chapter of the book. The first thing I want to talk about<br />

before we start dissecting <strong>Java</strong> and <strong>Java</strong>FX classes is the different types of events that are handled for games, from<br />

the arrow keys (DPAD on Smartphones) to keyboard (or remotes for iTV) to mouse (or trackball on Smartphones)<br />

to touchscreen (Smartphones and Tablets) to game controllers (Game Consoles and iTV Sets) to gyroscopes and<br />

accelerometers (Smartphones and Tablets) to motion controllers such as the Leap Motion and Razer Hydra Portal.<br />

Types of Controllers: What Types of Events Should We Handle?<br />

One of the key things to look at is what is the most logical approach to supporting game play related events, such<br />

as arrow keys; mouse clicks; touchscreen events; game controller buttons (A, B, C and D); and more advanced<br />

controllers, such as gyroscopes and accelerometers that are available on Android, Kindle, Tizen, and iOS consumer<br />

electronics devices. This decision will be driven by the hardware devices that a game is targeted to run on; if a game<br />

needs to run everywhere, then code for handling different event types, and even different programming approaches to<br />

event handling, will ultimately be required. We’ll take a look at what input events are currently supported in <strong>Java</strong> 8.<br />

It is also interesting to note that <strong>Java</strong> 8 and <strong>Java</strong>FX apps are already working on these embedded platforms, and<br />

I’d put money on native support on open platforms (Android, Tizen, Chrome, Ubuntu), and proprietary platforms<br />

that currently support <strong>Java</strong> technology (Windows, Blackberry, Samsung Bada, LGE WebOS, Firefox OS, Opera, etc.), at<br />

some point in time in the near future. The future of <strong>Java</strong> 8 is bright, thanks to <strong>Java</strong>FX and hardware platform support!<br />

www.it-ebooks.info<br />

195

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

Saved successfully!

Ooh no, something went wrong!