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

InvinciBagel.java Redesign: Adding Logical Methods<br />

The first thing that I want to do regarding the InvinciBagel.java code, which should already be open in a tab in<br />

NetBeans (if it is not, use the right-click and Op en work process), is to reorganize the current code using a half-dozen<br />

new methods that logically contain, as well as show, the different areas that we will need to address in order to add<br />

new Actors to our game. These include things such as managing event handling, adding new Image asset references,<br />

creating the new game Actor objects, adding the new actors to the Scene Graph, adding the new Actor objects to the<br />

CURRENT_CAST List we created in Chapter 10, and starting the GamePlayLoop AnimationTimer pulse engine.<br />

The first thing that we should do is to put those <strong>Java</strong> statements that need to be done first and that need to be in<br />

the .start() method itself at the top of the code. These create the Scene Graph root, a Scene object, and set up the<br />

Stage object:<br />

primaryStage.setTitle(InvinciBagel);<br />

root = new StackPane();<br />

scene = new Scene(root, WIDTH, HEIGHT, Color.WHITE);<br />

primaryStage.setScene(scene);<br />

primaryStage.show();<br />

As you can see in Figure 11-1, we are taking the root and scene object instantiations out of the method that is<br />

called .createSplashScreenNodes(), and putting these at the top of the .start() method. I am doing this because they<br />

are foundational to our InvinciBagel game (class). Next, we are also going to add six all-new method structures to our<br />

existing code. The only method that will remain untouched during this process is your .addNodesToStackPane(). You<br />

can see I’m calling the methods in a logical order: add events, add images, add actors, add Scene Graph, and add cast.<br />

Figure 11-1. Place basic configuration statements at top of the .start() method, and then the eight game method calls<br />

230<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!