Game Development Reference
In-Depth Information
CPU processing cycles for the many other things that we are going to be adding into
the game play that will need to use this “saved” processing overhead for other game
play-related logic.
You may be wondering why I have not added this same extended condition to the
else if(animator) portion of this programming structure. The reason is that this portion
of the loop will never be executed unless the first part, which we are excluding with
this new statement, is processed. This is because inside of the first part of this loop, we
set animator=true; and this will never happen (now that we have added the exten-
ded condition) if the up or down key is being pressed.
What is really cool about this is that the if(invinciBagel.isRight()) and
if(invinciBagel.isLeft()) conditional if() structures can now be used to
mirror all sprite cel state Image assets, when your player uses the left or right key to set
the direction that the character is traveling in, and only when the left and right keys
(only) are used to make the character run will the run-cycle part of this Java code pro-
cessing take place.
Make sure that you implement this same exact extended condition in your
if(invinciBagel.isLeft()) part of the conditional if() structure, as is shown
below, and which can be seen as well in Figure 13-13 .
if(invinciBagel. isLeft() ) {
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; }
}
}
 
Search WWH ::




Custom Search