Game Development Reference
In-Depth Information
Figure 12-8 . Make the same change to GamePlayLoop by adding an invinciBagel InvinciBagel variable and con-
structor
As you can see in Figure 12-8 , I have clicked on the invinciBagel variable (Invin-
ciBagel object reference) so it is highlighted, and you can see its usage across the two
methods. The declaration is used in the GamePlayLoop class, the instance inside of the
GamePlayLoop() constructor method is set using the InvinciBagel class this keyword
(using the iBagel parameter), and the variable reference inside of the .handle() method
accessed the Bagel class .update() method using the iBagel Bagel object and the invin-
ciBagel InvinciBagel reference object. Java is advanced, but cool.
Now that we have created our custom GamePlayLoop() constructor method that ac-
commodates the receipt of the InvinciBagel object reference named iBagel, and then
assigns it to the invinciBagel variable, it is time to return to the InvinciBagel.java code
(editing tab in NetBeans).
The final piece of this (second) puzzle of removing the static Bagel iBagel; declar-
ation is to add the Java this keyword in the GamePlayLoop() constructor method call.
After we do this, our InvinciBagel, Bagel and GamePlayLoop will all be wired up to
each other, without using any static variables (other than the WIDTH and HEIGHT
constants).
 
Search WWH ::




Custom Search