animationworld
play

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


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

  2. Pulsar Class Drawing the Pulsar public class Pulsar extends Sprite { public class Pulsar extends Sprite { ... color // instance variables public void drawState(Graphics g) { (x,y) minRadius } radius maxRadius (0,0) x // constructor (x,y) y Applet window V - 7 V - 8 } Updating the Pulsar Resetting the Pulsar public class Pulsar extends Sprite { public class Pulsar extends Sprite { ... ... public void updateState() { } public void resetState() { } V - 9 V - 10 } } PulsarAnimation Class BouncingBall Class public class BouncingBall extends Sprite { // instance variables 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); } // constructor } V - 11 V - 12

  3. Drawing the BouncingBall Resetting the BouncingBall public class BouncingBall extends Sprite { public class BouncingBall extends Sprite { ... ... public void drawState(Graphics g) { } (0,0) x public void resetState() { } y (x,y) Applet window V - 13 V - 14 Updating the BouncingBall BouncingBallAnimation Class (0,0) x public class BouncingBall extends Sprite { ... public void updateState() { public class BouncingBallAnimation extends Animation { y // 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); } (0,0) x } y } V - 15 V - 16 }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend