Game Development Reference
In-Depth Information
ment for you. The industry standard way to “correctly” utilize import static (or static
imports, if you wish) are for the import and use of constants, so we are in top conform-
ance with Java programming standard procedures here. Perform that same work pro-
cess again for the red error highlighting underneath the HEIGHT constant reference,
and then add the .setBoundaries() method call in between the .setXYLocation() and
.moveInvinciBagel() method calls in your .update() method. This would be done using
the following Java method call in the .update() method, shown in Figure 12-17 :
setBoundaries();
Figure 12-17 . Create rightBoundary, leftBoundary, bottomBoundary and topBoundary constants at the top of the
class
As you can see in Figure 12-17 , this will generate an error under the method call,
until we code the method.
Create a private void setBoundaries(){...} empty method structure
underneath the .setXYLocation() method structure, so that your methods are in the
same order that we will call them from inside of your .update() method. Next you will
place your four conditional if() structures, one for each screen boundary, starting with
the X axis related right and left screen boundaries, and then for the Y axis related bot-
tom and top screen boundaries. The first if statement needs to look at the rightBound-
ary value and compare the current iX location to that value. If the iX value is greater
than or equal to the rightBoundary value limit, then you want to set the iX value to
the rightBoundary value. This will keep the InvinciBagel locked into position right at
the boundary. The reverse of this logic will also work for the left side of the screen; if
the iX value is less than or equal to the rightBoundary value limit, then you will want
to set the iX value equal to the leftBoundary value.
 
 
Search WWH ::




Custom Search