AnimationWorld AnimationWorld uses Graphics to create animations. - - PDF document

animationworld
SMART_READER_LITE
LIVE PREVIEW

AnimationWorld AnimationWorld uses Graphics to create animations. - - PDF document

AnimationWorld AnimationWorld uses Graphics to create animations. Essentially, animations are a set of frames with Animation pictures where we flip through pictures one by one. V - 1 V - 2 AnimationWorld AnimationWorld An animation is


slide-1
SLIDE 1

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); } }

slide-2
SLIDE 2

V - 7

Pulsar Class

public class Pulsar extends Sprite { // instance variables // constructor

radius (x,y) color maxRadius minRadius

V - 8

Drawing the Pulsar

public class Pulsar extends Sprite { ... public void drawState(Graphics g) { } }

x y (0,0) Applet window

(x,y)

V - 9

Updating the Pulsar

public class Pulsar extends Sprite { ... public void updateState() { } }

V - 10

Resetting the Pulsar

public class Pulsar extends Sprite { ... public void resetState() { } }

V - 11

PulsarAnimation Class

public class PulsarAnimation extends Animation { // constructor public PulsarAnimation() { this.addSprite(new Pulsar(200,50,20,40,1,Color.red)); this.addSprite(new Pulsar(300,200,0,200,5,Color.blue)); this.setFps(12); } }

V - 12

BouncingBall Class

public class BouncingBall extends Sprite { // instance variables // constructor

slide-3
SLIDE 3

V - 13

Drawing the BouncingBall

public class BouncingBall extends Sprite { ... public void drawState(Graphics g) { }

x y (0,0) Applet window

(x,y)

V - 14

Resetting the BouncingBall

public class BouncingBall extends Sprite { ... public void resetState() { }

V - 15

Updating the BouncingBall

public class BouncingBall extends Sprite { ... public void updateState() { } }

x y (0,0) x y (0,0)

V - 16

BouncingBallAnimation Class

public class BouncingBallAnimation extends Animation { // constructor public BouncingBallAnimation() { this.addSprite(new BouncingBall(50,50,30,2,2,Color.magenta)); this.addSprite(new BouncingBall(150,150,25,3,-3,Color.cyan)); this.addSprite(new BouncingBall(250,250,40,1,4,Color.green)); this.setFps(12); } }