Game Development Reference
In-Depth Information
runningspeed variables and the programming logic that uses them might be taking up
memory when the player is using the up and down arrow keys, so I want to put a state-
ment in the top of the conditional if() structure that leaves the .setScaleX() sprite mir-
roring code intact but turns off the rest of the processing logic if the up and down keys
are being used. The Java code for excluding the run-cycle logic should be based on the
up and down arrow key variables both showing as false, indicating the player is using
the left or right keys
only
. This exclusion logic is seen in
Figure 13-12
, and looks like
the following Java code (shown in bold) addition:
if(invinciBagel.
isRight()
) {
spriteFrame.setScaleX(
1
);
if(
!animator
&& (
!invinciBagel.isDown()
&&
!invinciBagel.isUp()
) ) {
spriteFrame.setImage(imageStates.get(1));
if(framecounter >= runningspeed) {
animator=true;
framecounter=0;
} else { framecounter+=1; }
}
else if(animator) {
spriteFrame.setImage(imageStates.get(2));
if(framecounter >= runningspeed) {
animator=false;
framecounter=0;
} else { framecounter+=1; }
}
}