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

After that we removed the other two static modifier keywords on the StackPane and HBox objects, and made all<br />

of the rest of the variables private, at least for now, to provide the greatest level of encapsulation for the InvinciBagel<br />

(primary) game class.<br />

Next, we reorganized the code in the Bagel.java class relating to the .update() method. We created specific<br />

methods for polling the keypressed values and setting the iX and iY properties for the object, which we called the<br />

.setXYLocation() method, as well as creating the .moveInvinciBagel() method for calling the .setTranslate() methods.<br />

Finally, we created a new .setBoundaries() method in the Bagel.java class, which is called after the<br />

.setXYLocation() method but before the .moveInvinciBagel() method that makes sure that our main character stays<br />

on the screen at all times.<br />

In the next chapter, we are going take a look at advanced concepts regarding animating the game sprite as it<br />

is moved around your screen using the List ArrayList object, so that we get more realistic sprite<br />

animation before we get into advanced topics such as digital audio, collision detection, and physics simulation.<br />

www.it-ebooks.info<br />

271

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

Saved successfully!

Ooh no, something went wrong!