Game Development Reference
In-Depth Information
The next thing that we'll need to do to makes sure that our InvinciBagel and
GamePlayLoop classes (objects) can talk to each other is to make the GamePlayLoop()
constructor method compatible with (accept in the InvinciBagel this context reference
object inside of its parameter list) the InvinciBagel class's this object reference that we
need to send over to the GamePlayLoop class inside of the constructor method call.
Since we are currently depending on the Java compiler to create the GamePlayLoop()
constructor method for us, we will need to create one for ourselves! As you learned in
Chapter 3 , if you do not explicitly create a constructor method for a class, one will be
created for you.
Enhancing
GamePlayLoop.java:
Creating
a
GamePlayLoop() Constructor Method
Let's perform a similar work process in the GamePlayLoop.java class to what we did in
the Bagel.java class. Add a protected InvinciBagel invinciBagel;
statement at the top of the class. Next, create a public GamePlayLoop() constructor
method, with an InvinciBagel object named iBagel inside the parameter list. Inside the
GamePlayLoop() constructor method, set the iBagel InvinciBagel object reference
equal to the protected InvinciBagel invinciBagel (reference) variable so that we can
use the new invinciBagel InvinciBagel object reference inside of the GamePlayLoop
.handle() method. This will allow us to call the .update() method off of the iBagel Ba-
gel object using the invinciBagel InvinciBagel reference object. The GamePlayLoop
class and constructor method structure, along with a new .handle() method body, which
includes a revised invinciBagel.iBagel.update() method call path (object referencing
structure), are shown error-free in Figure 12-8 , and should look like the following Java
code:
public class GamePlayLoop extends AnimationTimer {
protected InvinciBagel invinciBagel ;
public GamePlayLoop(InvinciBagel iBagel ) {
invinciBagel = iBagel ;
}
@Override
public void handle(long now) {
invinciBagel .iBagel.update();.
}
}
 
Search WWH ::




Custom Search