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

As you can see in Figure 12-16, NetBeans is having trouble seeing the constants inside the InvinciBagel class.<br />

Figure 12-16. Hold a left arrow (or A) and up arrow (or W) key down at the same time, and move the Actor diagonally<br />

Mouse-over the wavy red error highlighting in NetBeans that is underneath the WIDTH constant, and select the<br />

import static invincibagel.InvinciBagel.WIDTH; option so that NetBeans will write this import statement for<br />

you. The industry standard way to “correctly” utilize import static (or static imports, if you wish) are for the import<br />

and use of constants, so we are in top conformance with <strong>Java</strong> programming standard procedures here. Perform that<br />

same work process again for the red error highlighting underneath the HEIGHT constant reference, and then add the<br />

.setBoundaries() method call in between the .setXYLocation() and .moveInvinciBagel() method calls in your .update()<br />

method. This would be done using the following <strong>Java</strong> method call in the .update() method, shown in Figure 12-17:<br />

setBoundaries();<br />

Figure 12-17. Create rightBoundary, leftBoundary, bottomBoundary and topBoundary constants at the top of the class<br />

268<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!