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-9. Add a third level of if-else nesting that prevents cels from alternating too quickly by using a framecounter<br />

Now make the same modifications to the if(invinciBagel.isLeft()) conditional if() structure. The only<br />

difference will be the ScaleX property being -1 (mirrored sprite image) as shown in the following code in Figure 13-10:<br />

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

spriteFrame.setScaleX(-1);<br />

if(!animator) {<br />

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

if(framecounter >= runningspeed) {<br />

animator=true;<br />

framecounter=0;<br />

} else { framecounter+=1; }<br />

} else if(animator) {<br />

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

if(framecounter >= runningspeed) {<br />

animator=false;<br />

framecounter=0;<br />

} else { framecounter+=1; }<br />

}<br />

}<br />

284<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!