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

}<br />

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

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

spriteFrame.setTranslateX(xLocation);<br />

spriteFrame.setTranslateY(yLocation);<br />

}<br />

@Override<br />

public void update() {<br />

// empty method<br />

}<br />

As you can see in Figure 14-8, this <strong>Java</strong> code is error-free, and everything that is needed to define and place a<br />

prop in the Scene (on the Stage) is in place, thanks to good design of the Actor (fixed) sprite class. This includes SVG<br />

collision shape data, the X and Y location (placement in the scene), and one or more Image assets. The reason that we<br />

included an .update() method in a fixed sprite class is to allow us to have animated (more than one Image cel) props if<br />

we want to get fancy later on in our game design process, and ratchet up the wow factor of the game’s visual design.<br />

Figure 14-8. Position a fixed sprite on the Stage in the constructor method using a .setTranslateX() and .setTranslateY()<br />

Next let’s create PropH, PropV, and PropB (which stands for “both”) classes. These will automatically mirror<br />

props for us around the X, Y or X and Y axes using the constructor method, so the object will inherently mirror images.<br />

Mirrored Prop Classes: Set the isFlip Property in the Constructor<br />

To make our process of building scenes easier, since everything (collision, location, animation) is part of a constructor<br />

method call, the difference between props is how they are mirrored (X or Y axis, or both axes). In this section, we are<br />

going to create variants of the Prop class that flip sprites for us, inside of a constructor method, so that all we have to<br />

do to get the effect we want is create that PropX object type. Create the first PropH class, as is shown in Figure 14-9.<br />

304<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!