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

Figure 13-16. Hold a left arrow (or A) and up arrow (or W) key down at the same time, and move the Actor diagonally<br />

Adding Jump and Evade Animation: Using the W and S Keys<br />

Let’s start to put into place the infrastructure for using another set of four keys to give our players more flexibility<br />

in implementing sprite (character) actions (animation). Using the keyboard, these would use the ASDW keys, and<br />

using a game controller, these would use the <strong>Java</strong>FX KeyCode class constants GAME_A, GAME_B, GAME_C, and<br />

GAME_D. I’ll be adding game controller event handling a bit later on during my game development after I add<br />

in more game play logic. The implementation of the basic jump and evade (projectiles) sprite cel Image assets<br />

would be accomplished by using the following two basic <strong>Java</strong> conditional if() structures for using the W key via<br />

if(invinciBagel.iswKey()) and the S key via if(invinciBagel.issKey()) processing structures, which are shown<br />

below, as well as in Figure 13-17:<br />

if(invinciBagel.iswKey()) {<br />

spriteFrame.setImage(imageStates.get(5));<br />

}<br />

if(invinciBagel.issKey()) {<br />

spriteFrame.setImage(imageStates.get(8));<br />

}<br />

www.it-ebooks.info<br />

293

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

Saved successfully!

Ooh no, something went wrong!