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 14 ■ Setting Up the Game Environment: Creating Fixed Sprite Classes Using the Actor Superclass<br />

Next, perform the same work process that you did for the PropV class, and create the PropB class. This class will<br />

set both the isFlipV and isFlipH properties to true, and implement a spriteFrame.setScaleX(-1); method call, as<br />

well as a spriteFrame.setScaleY(-1); method call. Your <strong>Java</strong> class structure for this last PropB class, which will mirror<br />

fixed prop imagery along both an X and Y axis, can be seen in Figure 14-16 and will look like the following code:<br />

public class PropB extends Actor {<br />

public PropB(String SVGdata, double xLocation, double yLocation, Image... spriteCels) {<br />

super(SVGdata, xLocation, yLocation, spriteCels);<br />

this.setIsFlipH(true);<br />

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

this.setIsFlipV(true);<br />

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

spriteFrame.setTranslateX(xLocation);<br />

spriteFrame.setTranslateY(yLocation);<br />

}<br />

}<br />

As you can see in Figure 14-16, the code is error-free, and you now have a PropB class, which will create fixed<br />

objects for your Scene that are flipped or mirrored around both the X and the Y axis at the same time! Having these<br />

four different fixed Prop classes will allow us to quickly and easily design Scene (and eventually, game levels)<br />

elements, without having to do anything but declare the correct prop class, and reference the correct Image asset and<br />

X,Y locus (location) and collision polygon SVG data.<br />

Figure 14-16. A completed PropB() constructor method creates a fixed PropB object flipped along both the X and Y axis<br />

Now we are ready to use these four new fixed sprite classes, and learn how to add Scene (Stage) elements.<br />

www.it-ebooks.info<br />

309

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

Saved successfully!

Ooh no, something went wrong!