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

Figure 13-10. Duplicate the if-else structure from the isRight() structure into the isLeft() structure using framecounter<br />

Now the time has come again to use the Run ➤ Project work process and test the run-cycle code, which now<br />

exhibits a smooth, even, realistic run cycle. You can fine tune the running speed to slightly slower with a 7 or 8 value<br />

or slightly faster with a 4 or 5 value. As we add faster vX values for running (say vX = 2) we can set the runningspeed to<br />

3 or 4 to match this and make the game far more realistic.<br />

One additional thing that I noticed as I was testing the code during this chapter that I want to correct here is the<br />

sprite cel image for landing. I have been using imageStates(3), which is the “landed” image, which should actually<br />

be better utilized with a collision situation. Let’s save this sprite cel image state for use later, in the collision detection<br />

code development phase, to signify a collision with a surface (just landed or on impact image). The image I want<br />

to use while the down arrow key is pressed is actually imageStates(6), which is the “preparing to land” image. The<br />

revised <strong>Java</strong> code will look like the following, and is shown highlighted in Figure 13-11:<br />

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

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

}<br />

www.it-ebooks.info<br />

285

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

Saved successfully!

Ooh no, something went wrong!