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

Figure 12-9. Add a <strong>Java</strong> this keyword inside of the GamePlayLoop() constructor method call to provide a context object<br />

As long as we are making our InvinciBagel.java class completely encapsulated, let’s make the StackPane root<br />

variable private as well, and get rid of the static modifier. Since I have moved the StackPane object named root back<br />

up into the .start() menu from the .createSplashScreenNodes() method, there is no good reason for a static modifier<br />

keyword. I am trying to remove all static modifiers (that are not constants) and “privatize” this class as much as I can.<br />

Removing the Rest of the Static Variables: StackPane and HBox<br />

Now I am going to start going right down the variable declaration lines of code at the top of the InvinciBagel.java<br />

class starting with the Boolean variables that we made private (which were public static), and see which of these<br />

variables I can make private instead of package protected static (which StackPane and HBox are currently), or<br />

which are package protected, and can be made private. A private variable “encapsulates” that variable’s data inside<br />

of the class (object) itself; in this case, this would be the InvinciBagel.java code that we’re currently refining. A<br />

package protected variable encapsulates the data inside of the package; in this case that would be the invincibagel<br />

package. The new <strong>Java</strong> statement for declaring the StackPane object named root, which is a root element of the<br />

Scene Graph, to be a private member of the InvinciBagel.java class (only), would be accomplished using the<br />

following code, shown in Figure 12-10.<br />

private StackPane root;<br />

www.it-ebooks.info<br />

261

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

Saved successfully!

Ooh no, something went wrong!