Game Development Reference
In-Depth Information
gel class (object) how, and where, to get to, and to execute, the public void
.isRight() {...} method structure, which will pass over the private boolean
right variable encapsulated in an InvinciBagel object. This is included here as a
demonstration of the Java OOP concept of “encapsulation.”
Your new .update() method body will use the same six lines of Java code, modified
to call the .is() methods on the inside of the if(condition=true) evaluation portion of
your existing conditional if structure. The new Java code, which is also shown in Fig-
ure 12-6 , should look like the following:
public void update() {
if(invinciBagel. isRight() ) { iX += vX; }
if(invinciBagel. isLeft() ) { iX -= vX; }
if(invinciBagel. isDown() ) { iY += vY; }
if(invinciBagel. isUp() ) { iY -= vY; }
spriteFrame.setTranslateX(iX);
spriteFrame.setTranslateY(iY);
}
Figure 12-6 . Insert the invinciBagel.is() method calls inside of the if statements, where the boolean variables used to
be
As you can see in Figure 12-6 , the code is error-free, and you now have an .up-
date() method that accesses the Boolean variables from your InvinciBagel.java class
without having to use any import static statements to do so.
 
 
Search WWH ::




Custom Search