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 7 ■ The Foundation of Game Play Loop: The <strong>Java</strong>FX Pulse System and the Game Processing Architecture<br />

Creating a GamePlayLoop Object: Adding Pulse Control<br />

Next, you need to declare, name, and instantiate a GamePlayLoop object named gamePlayLoop, using the new class<br />

you have created, in conjunction with the <strong>Java</strong> new keyword. Click the InvinciBagel.java tab, shown in Figure 7-9,<br />

and add a line of code below the Insets object declaration declaring the GamePlayLoop object, and name it<br />

gamePlayLoop, as follows:<br />

GamePlayLoop gamePlayLoop;<br />

Figure 7-9. Click the InvinciBagel.java editing tab, and declare a GamePlayLoop object named gamePlayLoop at the top<br />

As you can see, the code is error free, because NetBeans has found your GamePlayLoop class, which contains the<br />

overridden .handle() method and whose parent AnimationTimer class has a constructor method that can create an<br />

AnimationTimer (type of) object, using the GamePlayLoop class, extending AnimationTimer.<br />

Now, you have to instantiate, or create, an instance in memory of the GamePlayLoop object, using the <strong>Java</strong> new<br />

keyword. This is done once, when the game is first started, which means that the instance needs to go in the<br />

.start() method.<br />

You can do this after all the other Scene Graph Node objects and ActionEvent EventHandler objects have been<br />

created, using the following line of <strong>Java</strong> code (see also Figure 7-10):<br />

gamePlayLoop = new GamePlayLoop();<br />

152<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!