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

Figure 9-15. The current InvinciBagel package class (object) hierarchy, now that we have added Actor and Hero classes<br />

The Boolean flags set by the KeyEvent switch-case statements will be used in the .update() method and will<br />

move the InvinciBagel. The .handle() method in the GamePlayLoop object will call the .update() method, so there<br />

is a connection there as well. We are still making steady progress on our game engine framework, adding<br />

event handling!<br />

Summary<br />

In this ninth chapter, we added constants to our game Scene object creation so that we can change the supported<br />

display resolution at any time in the future, as well as adding a Color.WHITE background color using one of the other<br />

overloaded Scene() constructor methods. We did this so that we could finish our UI design and implement the PLAY<br />

GAME UI Button control so that it would hide the two ImageView image compositing plates that currently hold splash<br />

screen assets, and which can later hold game background digital image assets.<br />

We learned about the ImageView class (and object) visible characteristic (or attribute, or variable), and how to<br />

use the .setVisible() method call to toggle the visibility of a given ImageView image plate using true or false values.<br />

Since we turned the ImageView image compositing plate’s visibility off in the ActionEvent handling structure for the<br />

PLAY GAME Button, we then of course had to make sure that the visible attribute was set back to true (on or visible)<br />

for the other three Button UI controls in case your game player wanted to review any of these screens at a later time.<br />

Next we covered how to turn <strong>Java</strong> 7 compatible anonymous inner class event handling structures into a <strong>Java</strong> 8<br />

lambda expression using NetBeans. I wanted to cover <strong>Java</strong> 8 lambda expressions in this book, even though they are<br />

an advanced feature, because they are one of the major new features in <strong>Java</strong> 8, and this is a <strong>Java</strong> 8 programming title.<br />

Finally we got into adding new features to our <strong>Java</strong> 8 game programming infrastructure, and learned about input<br />

event (InputEvent) classes and subclasses and about how the event handler (EventHandler) class structures are set<br />

up, and how they span across the java.lang, java.util, javafx.event and javafx.scene.input packages. We took a look at<br />

KeyCode constants and at the KeyEvent class, and then implemented this KeyEvent handing in our <strong>Java</strong> game code,<br />

using .setOnKeyPressed() and .setOnKeyReleased() event handler structures for both <strong>Java</strong> 7 and <strong>Java</strong> 8 compatibility.<br />

In the next chapter, we are going to take a look at how to move a game sprite around your screen using this<br />

KeyEvent event handling structure that we have created during this chapter, as well as how to ascertain the boundary<br />

(edges) of the screen, character direction, movement velocity, and related animation and movement considerations.<br />

206<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!