Game Development Reference
In-Depth Information
The InvinciBagel Fly State: If KeyPressed Set im-
ageState(3 & 4)
The if(invinciBagel.isDown()) and the if(invinciBagel.isUp())
conditional if() structures are identical to the left and right key structures, except that
they call imageStates(3) and imageStates(4) List elements, to allow the InvinciBagel
character to “come in for landing” (cel 3), and “take off flying” (cel 4). As we add
more of the imageStates during this chapter, and combine this cel animation code with
our motion and boundary code, you are going to have more and more fun testing this
chapter's coding results! If you want to take a programmer's shortcut, copy and paste
the .isRight() and .isLeft() constructs underneath themselves, and simply change the
.get(1) and .get(2) to .get(3) and .get(4). As you can see in Figure 13-4 , the code is cur-
rently very compact and well organized; structured; and logical; and in only half a
dozen lines of Java code, we have now implemented more than half of our nine image
states already! Of course, we still have to add refinement code, to implement sprite
mirroring for direction changes and run-cycle timing refinement. The Java code for the
.isUp() and .isDown() method structures should look like the following:
if(invinciBagel.isDown()) {
spriteFrame. setImage (imageStates. get(3) );
}
if(invinciBagel.isUp()) {
spriteFrame. setImage (imageStates. get(4) );
}
 
Search WWH ::




Custom Search