Game Development Reference
In-Depth Information
imageStates(1) or imageStates(2) sprite cels, from the List<Image> object, instead of
using the imageStates(0) sprite cel. The Java code to change the sprite Image states to
state 1 or 2, if the right or left key is pressed (true), should look like the following:
if(invinciBagel. isRight ()) {
spriteFrame. setImage (imageStates. get(1) );
}
if(invinciBagel. isLeft ()) {
spriteFrame. setImage (imageStates. get(2) );
}
As you can see in Figure 13-3 , the Java code is error-free, and we are ready to use
the Run > Project work process test this preliminary run mode. If you quickly press
the left and right arrow keys in succession, you'll see the InvinciBagel running!
Figure 13-3 . Add conditional if() statements that check for left/right movement, and sets the run sprite image states
Since this is not how we want to make our game player make the InvinciBagel run
(because the very nature of it stops his movement around the screen, and because it's
just plain lame), let's quickly put into place your up and down key support, so that we
can come back and work on the left and right keys so we can make the run cycle work!
 
 
Search WWH ::




Custom Search