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 13 ■ Animating Your Action Figure States: Setting the Image States Based on KeyEvent Processing<br />

});<br />

scene.setOnKeyReleased(KeyEvent event) -> {<br />

switch (event.getCode()) {<br />

case UP: up = true; break;<br />

case DOWN: down = true; break;<br />

case LEFT: left = true; break;<br />

case RIGHT: right = true; break;<br />

case W: wKey = true; break;<br />

case S: sKey = true; break;<br />

case A: aKey = true; break;<br />

case D: dKey = true; break;<br />

}<br />

});<br />

As you can see in Figure 13-14, the code is error-free, because I added wKey, sKey, aKey, and dKey variables to<br />

the Boolean up, down, left, right compound declaration statement located at the top of the InvinciBagel.java class.<br />

Figure 13-14. Create event handling for the WSAD keys specifically, by using wKey, sKey, aKey, and dKey variables<br />

Next, we need to use the Source ➤ Insert Code ➤ Generate ➤ Getters and Setters work process, to have<br />

NetBeans write the eight .is() and .set() methods for us, so that we can access the variables in our Bagel.java class.<br />

290<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!