CHAPTER 10 ■ ANIMATION
Figure 10-5. The MouseSprite program
I can catch only two bullseyes in the screen shot. This problem of trying to catch the animation in
motion is one reason why animation programmers often add switches to slow or stop the animation. For
non-game animations (such as rotating medical images or animations used in court), slow, pause, and
fast forward options are essential. Another good exercise is to add a stop feature to the MouseSprite
program (perhaps a right-click can stop and start the animation).
The MouseSprite class draws a different image for each part of its process and then sets a flag to
indicate that it's done. As we saw previouslly, the class (MouseSpritePanel) that manages the individual
MouseSprite objects can then detect when to remove the MouseSprite object.
Summary
In this chapter, we covered the basics of creating animations with Java. In particular, we discussed the
following:
- How to draw on the screen with Java's Graphics package
- How to use a thread to control an animation
- How to use a timer to control an animationHow timers give better control than
threads, so we should prefer timers - How to create a timed animation
- How to create a triggered animation