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

Figure 14-25. Instantiate an iPB0 PropB object, add it to the root Scene Graph, and add it to a CurrentCast List<br />

Next, let’s add the ImageView Node for the iPB0 PropB object into the Scene Graph root object. This is done<br />

using a .getChildren().add() method chain. This references a spriteFrame ImageView object, which is inside of<br />

the iPB0 PropB object, using dot notation. This is done using the following <strong>Java</strong> statement, which is also shown in<br />

Figure 14-25:<br />

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

Finally, we’ll use the .addCurrentCast() method that we created in Chapter 10 to add this iPB0 PropB object to<br />

a CURRENT_CAST List ArrayList object, inside of the castDirector CastingDirector object, which can<br />

be seen at the bottom of Figure 14-25, and which uses this following single line of <strong>Java</strong> code:<br />

castDirector.addCurrentCast(iPB0);<br />

Now that we’ve put all four of the Actor subclasses that we have created during the first half of this chapter into<br />

service, we can test the application and see what the different X and Y axis mirroring does to the prop0.png brick.<br />

316<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!