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

As you can see, the InvinciBagel character is behind the Prop object, which means that we need to change<br />

the order of the <strong>Java</strong> statements inside of the .addGameActorNodes() method, since the order that Node objects<br />

are added to the Scene Graph determines their z-index or z-order. As you can see in Figure 14-23, I have moved<br />

the .add() method call to add iPR0 above the one for iBagel, so as you can see on the right side of Figure 14-22, the<br />

InvinciBagel character is now on top of the Prop object. Once we add collision detection this will not be an issue, of<br />

course. Let’s use the same work process and add a PropH object into the scene, so that I can show you how this tile<br />

image can be flipped and mirrored to create seamless tileable constructs for your <strong>Java</strong> 8 game development.<br />

Let’s use the same naming convention and name the PropH object iPH0. The <strong>Java</strong> instantiation statement, which<br />

can be seen in Figure 14-23, should look like the following line of <strong>Java</strong> code:<br />

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

Figure 14-23. Instantiate an iPH0 PropH object, add it to the root Scene Graph, and add it to a CurrentCast List<br />

Our next step in adding a fixed sprite prop, is adding the ImageView Node object for the iPH0 PropH object, into<br />

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

the spriteFrame ImageView object that lives inside of the iPH0 PropH object, by using dot notation. This is done<br />

using the following <strong>Java</strong> statement, which is also shown in Figure 14-23:<br />

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

Finally, we will use the .addCurrentCast() method that we created in Chapter 10, to add this iPH0 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, also shown at the bottom of Figure 14-23:<br />

castDirector.addCurrentCast(iPH0);<br />

As you can see in Figure 14-23, I have also changed the 0,0 coordinates for the Prop object to 0,148, and the<br />

coordinates for the PropH object to 72,148. This will place the Y-axis mirrored PropH object seamlessly to the right of<br />

the Prop object. If you want to see the seamless tiling effect now, you can use your Run ➤ Project work process. If you<br />

don’t have your NetBeans 8 IDE running currently, and you want to look ahead to Figure 14-26, you can see this tiling<br />

(mirroring) effect now. Eventually, I’m also going to integrate the PropV and the PropB classes (objects) into this tiling.<br />

314<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!