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, let’s instantiate the Image object that holds one of the prop images, a tileable brick, so that we can use our<br />

four InvinciBagel.java methods, .loadImageAssets(), .createGameActors(), .addGameActorNodes(), and, finally,<br />

.createCastingDirection() to install fixed Prop objects into our game’s Scene object, and onto our game’s Stage object.<br />

Instantiate Image Objects: Using the .loadImageAssets( ) Method<br />

Open the InvinciBagel.java tab in NetBeans and open the loadImageAssets() method. Now add an iP0 Image object<br />

instantiation statement referencing the prop0.png file and its 72x32 pixel size. The <strong>Java</strong> code to create the iP0 Image<br />

object, which you can see in Figure 14-20, should look like the following <strong>Java</strong> statement:<br />

iP0 = new Image("/prop0.png", 72, 32, true, false, true);<br />

Figure 14-20. Add the iP0 Image object instantiation using the prop0.png file name and the 72 by 32 pixel image size<br />

Now we’re ready to add our first Prop object to our game to add a fixed sprite, which will allow us to create our<br />

game design using classes that we’re putting into place in our invincibagel package code base during this chapter.<br />

Adding Fixed Sprites Using Prop Objects: .addGameActors( )<br />

After your .loadImageAssets() method there are three other method “containers” that we designed for our use during<br />

the game design process, for adding Actor objects into this game. These are called in the order that we need to utilize<br />

them for this process, so let’s continue to be organized, and use them in that order. The first instantiation that we will<br />

need to perform creates a new (using the <strong>Java</strong> new keyword) Prop object. We will use our “dummy” SVG shape data<br />

again for now, as well as the 0,0 center of the screen X and Y locations, and finally, the iP0 Image asset, which we just<br />

declared and instantiated during the previous sections of this chapter. The <strong>Java</strong> instantiation statement, which can be<br />

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

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

312<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!