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 11 ■ Moving Your Action Figure in 2D: Controlling the X and Y Display Screen Coordinates<br />

The Actor Image Assets Loading Method: .loadImageAssets()<br />

Now that we have declared the nine Image objects for use at the top of our InvinciBagel.java class, the next thing that<br />

we will need to do is to copy the nine PNG32 sprite images, which are named sprite0.png through sprite8.png, into<br />

the /src folder for our InvinciBagel NetBeans project. This is done using the file management utility for your operating<br />

system; in the case of my 64-bit Windows 7 OS it is the Windows Explorer utility, shown in Figure 11-4, with the Image<br />

assets copied into the C:/Users/user/MyDocuments/NetBeansProjects/InvinciBagel/src folder. All of the PNG<br />

image assets are PNG32 (24-bit RGB true color data with a 8-bit 256 gray level alpha channel) except for the back plate<br />

for the splashscreen, which is a PNG24, as it does not need an alpha channel because it is a background image plate.<br />

Figure 11-4. Copy the sprite0.png through sprite8.png files into your NetBeansProjects/InvinciBagel/src project folder<br />

Now we are ready to code the private void loadImageAssets(){...} method. Once you create a method<br />

body (declaration), you will want to copy the four Image object instantiations from your .createSplashScreenNodes()<br />

method so that all of the Image object loading is done in one central location for your game application. After that is<br />

done, you can copy and paste the scoresLayer Image instantiation and create iB0 through iB8 Image instantiations. Be<br />

sure to set the image size to 81 pixels (X and Y) and use the correct file name references, shown in the following code:<br />

private void loadImageAssets() {<br />

splashScreen = new Image("/invincibagelsplash.png", 640, 400, true, false, true);<br />

instructionLayer = new Image("/invincibagelinstruct.png", 640, 400, true, false, true);<br />

legalLayer = new Image("/invincibagelcreds.png", 640, 400, true, false, true);<br />

scoresLayer = new Image("/invincibagelscores.png", 640, 400, true, false, true);<br />

iB0 = new Image("/sprite0.png", 81, 81, true, false, true);<br />

iB1 = new Image("/sprite1.png", 81, 81, true, false, true);<br />

iB2 = new Image("/sprite2.png", 81, 81, true, false, true);<br />

iB3 = new Image("/sprite3.png", 81, 81, true, false, true);<br />

iB4 = new Image("/sprite4.png", 81, 81, true, false, true);<br />

iB5 = new Image("/sprite5.png", 81, 81, true, false, true);<br />

iB6 = new Image("/sprite6.png", 81, 81, true, false, true);<br />

iB7 = new Image("/sprite7.png", 81, 81, true, false, true);<br />

iB8 = new Image("/sprite8.png", 81, 81, true, false, true);<br />

}<br />

234<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!