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 12 ■ Setting Boundaries for Your Action Figure in 2D: Using the Node Class LocalToParent Attribute<br />

Enhancing GamePlayLoop.java: Creating a GamePlayLoop( ) Constructor Method<br />

Let’s perform a similar work process in the GamePlayLoop.java class to what we did in the Bagel.java class. Add a<br />

protected InvinciBagel invinciBagel; statement at the top of the class. Next, create a public GamePlayLoop()<br />

constructor method, with an InvinciBagel object named iBagel inside the parameter list. Inside the GamePlayLoop()<br />

constructor method, set the iBagel InvinciBagel object reference equal to the protected InvinciBagel invinciBagel<br />

(reference) variable so that we can use the new invinciBagel InvinciBagel object reference inside of the<br />

GamePlayLoop .handle() method. This will allow us to call the .update() method off of the iBagel Bagel object using<br />

the invinciBagel InvinciBagel reference object. The GamePlayLoop class and constructor method structure, along<br />

with a new .handle() method body, which includes a revised invinciBagel.iBagel.update() method call path (object<br />

referencing structure), are shown error-free in Figure 12-8, and should look like the following <strong>Java</strong> code:<br />

public class GamePlayLoop extends AnimationTimer {<br />

protected InvinciBagel invinciBagel;<br />

public GamePlayLoop(InvinciBagel iBagel) {<br />

invinciBagel = iBagel;<br />

}<br />

@Override<br />

public void handle(long now) {<br />

invinciBagel.iBagel.update();.<br />

}<br />

}<br />

Figure 12-8. Make the same change to GamePlayLoop by adding an invinciBagel InvinciBagel variable and<br />

constructor<br />

www.it-ebooks.info<br />

259

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

Saved successfully!

Ooh no, something went wrong!