28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14 ■ Setting Up the Game Environment: Creating Fixed Sprite Classes Using the Actor Superclass<br />

Let’s use the exact same work process, and add a PropV object into the scene, so that we can see how this tile<br />

image can be flipped and mirrored around the X axis, to create even more complex seamless tileable constructs for<br />

your <strong>Java</strong> 8 game development. Let’s use the same naming convention, and name this new PropV object iPV0. Your<br />

new <strong>Java</strong> instantiation statement, which can be seen in Figure 14-24, should look like the following line of <strong>Java</strong> code:<br />

iPV0 = new PropV("M150 0 L75 200 L225 200 Z", 0, 0, iP0);<br />

The next logical step to adding a fixed sprite prop, is to add the ImageView Node object for this iPV0 PropV object<br />

into the Scene Graph root StackPane object. This is accomplished using the .getChildren().add() method chain,<br />

which references the spriteFrame ImageView object, which lives inside of the iPV0 PropV object, using dot notation.<br />

This can be accomplished by using the following <strong>Java</strong> programming statement, which is also shown in Figure 14-24:<br />

root.getChildren().add(iPV0.spriteFrame);<br />

Finally, we will use the .addCurrentCast() method, that we created in Chapter 10, to add this iPV0 object to the<br />

CURRENT_CAST List ArrayList object, inside of the castDirector CastingDirector object, using the following<br />

line of <strong>Java</strong> code, which is also shown at the very bottom of Figure 14-24:<br />

castDirector.addCurrentCast(iPV0);<br />

Figure 14-24. Instantiate an iPV0 PropV object, add it to the root Scene Graph, and add it to a CurrentCast List<br />

Finally, let’s add a PropB object into the scene, so that I can show you how your tileable image can be flipped<br />

(mirrored) around both the X and the Y axes at the same time. We’ll follow our naming convention, naming the PropB<br />

object iPB0. The instantiation statement, which can be seen in Figure 14-25, should look like the following <strong>Java</strong> code:<br />

iPB0 = new PropB("M150 0 L75 200 L225 200 Z", 0, 0, iP0);<br />

www.it-ebooks.info<br />

315

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

Saved successfully!

Ooh no, something went wrong!