Game Development Reference
In-Depth Information
Figure 12-4 . Add an InvinciBagel object variable named invinciBagel, and add the object into the constructor method
Next, let's add the InvinciBagel context object into the front of the Bagel() con-
structor's parameter list, since we can't put it at the end of the parameter list, because
we're using the end of the parameter list to hold our Image... List (or Array, at some
point in the code it is both of these) specification. Inside of the constructor method it-
self, you'll set the InvinciBagel reference object, which is passed into the constructor
method using the name iBagel , to equal an invinciBagel variable, which you have
already declared at the top of the Bagel.java class. This would all be done using the fol-
lowing modified Bagel() constructor method structure, which can be seen highlighted
at the top of Figure 12-4 :
public Bagel(InvinviBagel iBagel , String SVGdata, double
xLocation, double yLocation,
Image... spriteCels) {
super(SVGdata, xLocation, yLocation, spriteCels);
invinciBagel = iBagel ;
}
As you can see in Figure 12-4 , our code is error-free, and we are ready to go back
into our InvinciBagel.java class and add the Java this keyword into the Bagel() con-
structor method call. Doing this will pass an InvinciBagel class (object) reference ob-
ject over to the Bagel.java class (object) so that we will be able to use the .is() and
.set() methods from the InvinciBagel class without having to specify any import state-
ments whatsoever. You can also delete the four import static statements at the top of
your Bagel.java class. As you can see in Figure 12-4 , I have deleted these static import
statements already.
 
Search WWH ::




Custom Search