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

Powering the iBagel Actor: Using the GamePlayLoop<br />

Next let’s “wire up” or make the connection between these game engines that we have been putting into place in our<br />

game code infrastructure during the first half of the book. The first thing that we will need to do is to tell our GamePlay<br />

Engine in the GamePlayLoop AnimationTimer subclass that we want to have it look at (update) the iBagel Bagel<br />

object on every pulse. There are two major lines of code that we will need to install in the GamePlayLoop.java class<br />

for this to happen. The first is a reference to the static Bagel object named iBagel that we declared in the code that is<br />

shown in Figure 11-3 using the import static invincibagel.InvinciBagel.iBagel <strong>Java</strong> statement. The second line<br />

of code that we need to install will live inside of the .handle() method, and will serve to “wire” the .handle() method<br />

(the pulse engine) to the iBagel object using its .update() method. The new GamePlayLoop class import statements<br />

and .handle() method should look like the following <strong>Java</strong> code, shown error-free in Figure 11-11:<br />

import javafx.animation.AnimationTimer;<br />

import static invincibagel.InvinciBagel.iBagel;<br />

public class GamePlayLoop extends AnimationTimer {<br />

@Override<br />

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

iBagel.update();<br />

}<br />

}<br />

Figure 11-11. Add a <strong>Java</strong> statement inside of the GamePlayLoop .handle() method invoking an iBagel.update() method<br />

242<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!