V - 1
Animation
V - 2
AnimationWorld
AnimationWorld uses Graphics to create animations. Essentially, animations are a set of frames with pictures where we flip through pictures one by one.
V - 3
AnimationWorld
There are 2 main parts to AnimationWorld:
- Sprites - A sprite is an object that moves in an animation
(Sprites are like actresses and actors. We will create a library of Sprites which will “act” in the animation.)
- Animations - An animation can be thought of as a script
for the Sprites. It includes information such as which Sprites are in the animation, when these Sprites move, etc.
V - 4
AnimationWorld
- An animation is created by showing a sequence of
frames
- The frames are numbered starting from 1
- After the first frame, all other frames are created by
updating each Sprite and then painting the Sprite on a new frame
V - 5
Creating New Sprites
public class Pulsar extends Sprite { // instance variables ... // constructors ... // instance methods // Describes how to draw the Sprite in a particular frame public void drawState(Graphics g) {...} // Describes how to update the state of the Sprite // between frames public void updateState() {...} // Describes how to reset the state of the Sprite back to // its initial state public void resetState() {...} }
V - 6
Creating New Animations
public class PulsarAnimation extends Animation { // constructor public PulsarAnimation() { this.addSprite( // add Sprite here ); this.addSprite( // add Sprite here ); this.setFps(12); } }