Game Development Reference
In-Depth Information
CHAPTER 13
Animating Your Action Figure
States: Setting the Image States
Based on KeyEvent Processing
Now that we have also organized your Java code into logical methods in the Bagel.java
class, as well as making sure that all of our Java code is standards compliant in Chapters
11 and 12 , it is time to get into some more complicated code structures that will animate
our InvinciBagel character on the screen as the user moves the character. For instance, if
the character is traveling due East or due West (using only left or right keypresses, to
travel in a straight line), he should be running (alternating between the imageStates(1)
and imageStates(2) List<Image> elements). If the up key is also pressed, he should be
leaping up in the direction of the left or right keypress, and if the down key is pressed,
he should be preparing to land in the direction of the left or right keypress.
We will also need to implement the Actor class's isFlipH property or attribute, so
that the character is facing the right way based upon the direction he is traveling. Instead
of using another image for that, we will use the JavaFX capability to “flip” or “mirror”
any image around its central Y axis (isFlipH) or around its central X axis (isFlipV).
Once a sprite animation state is combined with the movement code that you put into
place in the previous chapter, you'll be amazed at how realistic this character will be-
come, and we are still using only nine sprite state images (under 84KB of total data foot-
print used for our new media assets so far).
We will do all of this character animation during this chapter using only Java code,
and using only the JavaFX AnimationTimer (GamePlayLoop) superclass. This way, we
are optimizing the use of the JavaFX pulse engine for our game by accessing the pulse
event timing engine using only the javafx.animation package's class that uses the least
Search WWH ::




Custom Search