Game Development Reference
In-Depth Information
Figure 12-13 . Create a .moveInvinciBagel() method for .setTranslate() method calls, and call if from .update() meth-
od
Next, let's move an iBagel on the screen using the ImageView .setTranslateX() and
.setTranslateY() methods.
Further Modularization of the .update() Method:
.setXYLocation()
You might think that the KeyEvent handling Boolean variables need to be processed in-
side of the .update() method, but since they are simply evaluated and then increment
the Bagel object's iX and iY properties, this can be placed into its own .setXYLoca-
tion() method as well, leaving us with only top-level method calls inside of our .up-
date() method. This will make further sprite manipulation and game play development
much more organized, and will also help us to see what code is being performed at
what stages in the .update() cycle. What we are going to do, which is also shown in
Figure 12-14 , is to create a .setXYLocation() method, which we will call first in our
.update() method, and then place the four conditional if() statements inside of this new
private void setXYLocation(){...} method structure. The new three
method structure for our Bagel.java class .update() “chain of command” will utilize the
following Java code:
public void update() {
setXYLocation();
moveInvinciBagel( iX , iY );
}
 
 
Search WWH ::




Custom Search