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

As you can see in Figure 11-6, the code is error-free, and you now have an iBagel Bagel object that you can now<br />

use to start to develop the InvinciBagel sprite movement around the game play stage, which is usually the entire<br />

display screen. We’ll be wiring this Bagel Actor up to the <strong>Java</strong>FX pulse timing engine a bit later on during this chapter.<br />

Figure 11-6. Add a private void createGameActors() method; add an iBagel object instantiation via Bagel() constructor<br />

In case you’re wondering what the SVGdata String object “M150 0 L75 200 L225 200 Z” does, it is shorthand for<br />

the following line drawing instructions (commands). The M is a “Move Absolute” command and tells the line draw<br />

(or in this case a path draw) operation to start at location 150,0. The L is a “Line Draw To” command and tells the SVG<br />

data to draw a line from 150,0 to 75,200. The second L draws a line from 75,200 to 225,200, giving us two sides of the<br />

triangle shape. The Z is a “Close Shape” command, which, if the shape is open, as ours is currently, will draw a line<br />

to close the shape. In this case, that would equate to drawing a line from 225,200 to 150,0, giving us three sides to our<br />

triangle shape, closing the open path, and giving us a valid collision detection boundary.<br />

We will be replacing this with a more complex collision shape later on, during Chapter 16 covering collision<br />

detection polygon creation, SVG data, and collision detection logic. Our actual collision polygon will contain many<br />

more numbers, making our Bagel() constructor method call unwieldy. As you might imagine, at that point in the game<br />

(no pun intended), I will probably create a work process that will be used specifically for constructing collision shapes.<br />

This work process will show you how to generate SVG polygon data using GIMP so that you can place SVG data into<br />

its own String object, and reference that in your Actor object constructor. If you wanted to turn collision data creation<br />

into its own method as well, this is how that would look, using a (theoretical) .createActorCollisionData() method:<br />

String cBagel; // Create String variable named cBagel (collision data Bagel) at top of class<br />

private void createActorCollisionData() {<br />

cBagel = "M150 0 L75 500 L225 200 Z";<br />

}<br />

private void createGameActors() {<br />

iBagel = new Bagel(cBagel, 0, 0, iB0,iB1,iB2,iB3,iB4,iB5,iB6,iB7,iB8);<br />

}<br />

236<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!