Game Development Reference
In-Depth Information
You have added quite a significant amount of “wow factor” into this game's
primary InvinciBagel character, during this chapter covering animation. This will go a
long way toward making this a popular game across age groups.
Summary
In this thirteenth chapter, we implemented sprite animation across the InvinciBagel ap-
plication using highly optimized code. We combined seven basic sprite shapes with the
key movement that we developed in Chapter 11 and the boundary detection that we de-
veloped in Chapter 12 to create a fully animated InvinciBagel character that really
comes alive, and does so based on the use of six basic game play control keys (up,
down, left, right, W, and S).
We learned how to use the JavaFX ImageView class ScaleX property with its spe-
cial -1 use case setting to flip or mirror the Image asset that is inside of the ImageView
“Image container” around the Y axis. This allows us to create 36 sprite image states us-
ing only 9 basic sprite states, which we have imported as Image assets, into a
List<Image> ArrayList object. This is a form of optimization, as it allows us to use less
than 84KB of image assets instead of 336KB of Image assets for our primary game su-
perhero, the InvinciBagel character.
Next, we learned how to implement a Boolean animator variable, which we used
to animate between two different sprite cel run states, imageStates(1) and im-
ageStates(2) in our List. The resulting run cycle was too rapid for professional use, so
next, we then added a framecounter variable, to slow the movement down, and a run-
ningspeed variable, allowing us to implement a fine-tuned control over the sprite's
running speed, which we will be able to take advantage of in later on in our game play
logic.
Next we optimized our code so that the variables and processing code used for the
run cycle were not used if the run cycle was not showing, that is, if the InvinciBagel is
flying or landing. We also made sure to set the isFlipH property in our Actor superclass
(and therefore in our Bagel object) using the this.setIsFlipH() method call.
Next we added four new game play control keys in our event handling code in the
InvinciBagel.java class, and added four new private Boolean variables aKey, sKey,
dKey, and wKey, and had NetBeans create Getter and Setter methods for them auto-
matically. After we made that enhancement, we added the sprite evade action image to
the S key and the sprite jump over action image to the W key to make our game a two-
hand game and to get ready to make the game prepared to use professional game con-
troller hardware.
Search WWH ::




Custom Search