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-17. Add if() statements at the bottom of the method for .iswKey() and issKey for Jump and Evade animation<br />

Now we have implemented imageStates(0), imageStates(1), imageStates(2), imageStates(4), imageStates(5),<br />

imageStates(6), and imageStates(8) in our game event handling and character animation processing. The other sprites<br />

are better suited for use with collision detection, so let’s save those for later chapters in the book.<br />

Last Minute Details: Setting the isFlipH Property<br />

Next, I want to add in two more lines of code for what I call “bookkeeping,” because we have installed isFlipH and<br />

isFlipV properties in our Actor superclass, so if we mirror sprites around the X or Y axis, we need to be sure to set these<br />

variables correctly, to reflect that (no pun intended) change to the Actor object, so that we can use this information<br />

in other areas of our game application programming logic. We will do this using the <strong>Java</strong> this keyword, to refer to the<br />

iBagel object that we are coding for in the Bagel.java class, and call the .setIsFlipH() method, using a false value if<br />

ScaleX property has been set to 1, or a true value if the ScaleX property has been set to a value of -1. It is important to<br />

294<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!