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

to remove the private modifier or replace it with a different modifier keyword for any reason, we can, but it is best to<br />

work from a place of total object encapsulation if possible from the start, and then open up the object if we need to<br />

later on. The <strong>Java</strong> code statements for making all data fields inside of our InvinciBagel class encapsulated are:<br />

private Scene scene;<br />

private Image splashScreen, instructionLayer, legalLayer, scoresLayer;<br />

private Image iB0, iB1, iB2, iB3, iB4, iB5, iB6, iB7, iB8;<br />

private ImageView splashScreenBackplate, splashScreenTextArea;<br />

private Button gameButton, helpButton, scoreButton, legalButton,;<br />

private Insets buttonContainerPadding;<br />

private GamePlayLoop gamePlayLoop;<br />

private CastingDirector castDirector;<br />

As you can see in Figure 12-12, the code for all of the classes and modifications we have made thus far are errorfree,<br />

and we are ready to build more complex <strong>Java</strong> statements that control our primary character sprite on top of<br />

technically correct <strong>Java</strong> code that follows industry standard <strong>Java</strong> 8 programming practices.<br />

Figure 12-12. Make all of the variable declarations after the iBagel Bagel object declaration use private access control<br />

Next, we will get back into our Bagel.java class, and the .update() method, and start to refine (and organize) that<br />

code into more logical methods, so that our .update() method becomes more of a “top-level” method, that calls lowerlevel<br />

method “<strong>Java</strong> code blocks” that implement things such as key event processing, character movement, screen<br />

boundaries, sprite Image state, and so on.<br />

This will allow us to put a more complex “workload” on the Bagel character’s .update() method by calling logical<br />

methods such as .setXYLocation(), .moveInvinciBagel(), and .setBoundaries(), and later on during this book,<br />

.setImageState(), .checkForCollision() and .playAudioClip() for example. In this way, your .update() method calls<br />

other methods containing logical code blocks. This keeps your <strong>Java</strong> code well organized and makes programming<br />

logic easier to visualize.<br />

264<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!