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

As you can see in Figure 11-5, your code is error-free, which means that you have copied your sprite assets into<br />

the proper /src folder, and you now have more than a dozen digital image assets installed for use in your game.<br />

Figure 11-5. Create a private void loadImageAssets() method, add the iB0 through iB8 and splashScreen Image objects<br />

Now that the assets you need to call your Bagel() constructor method that you created in Chapter 10 are in<br />

place, we can move on to creating a method that holds our game asset creation <strong>Java</strong> code. This amounts to calling<br />

the constructor methods for each of the Actor subclasses we eventually create, the first of which was the Bagel class,<br />

which we created first so that we can start to work on getting our primary character moving around the screen.<br />

Creating Your InvinciBagel Bagel Object: .createGameActors()<br />

The next step in the game actor creation process after loading your image assets is to call the constructor method for<br />

the game actor. To be able to do this, you must first subclass either the Actor superclass (for fixed game actors, which<br />

could be called “props”) or the Hero superclass (for motion game actors, such as the Hero, his enemies, and the like).<br />

I am going to create a .createGameActors() method to hold these instantiations, because even though initially there is<br />

only going to be one line of code inside of the body of this method, eventually, as the game becomes more and more<br />

complex, this method will serve as a “roadmap” regarding what game actor assets we have installed. This method will<br />

be declared as a private method, since the InvinciBagel class will be controlling the creation of these game actors, and<br />

will feature a void return type, because the method doesn’t return any values to the calling entity (the .start() method<br />

in this case). Inside of the method we’ll call the Bagel() constructor method, using some “placeholder” SVG path data,<br />

as well as a 0,0 initial X,Y screen location, and finally, the nine sprite cels using a comma-delimited list at the end of<br />

the constructor method call. The method body and object instantiation will use the following three lines of <strong>Java</strong> code:<br />

private void createGameActors() {<br />

iBagel = new Bagel("M150 0 L75 500 L225 200 Z", 0, 0, iB0,iB1,iB2,iB3,iB4,iB5,iB6,iB7,iB8);<br />

}<br />

www.it-ebooks.info<br />

235

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

Saved successfully!

Ooh no, something went wrong!