Animation class.
Only one method, initializeAnimation() needs to be implemented.
Inside this method, we can set properties for the Animation as well as
add Sprites and signal when they should appear/disappear, be active/inactive.
Methods that we can use fall into four categories.
setFps(int newFps)setNumberFrames(int frames)Animation.NO_MAX_FRAMES
setNumberRepeats(int repeats)Animation.FOREVER
setFrameSize(int width, int height)addSprite(Sprite s)addSprite(Sprite s, String name)Cue class in Java.
setActive (Sprite s, int frameNumber)setVisible (Sprite s, int frameNumber)setActiveAndVisible (Sprite s, int frameNumber)setInactive (Sprite s, int frameNumber)setHidden (Sprite s, int frameNumber)setInactiveAndHidden (Sprite s, int frameNumber)setActiveAndVisibleRange (Sprite s, int startFrameNumber, int endFrameNumber)setInactiveAndHiddenRange (Sprite s, int startFrameNumber, int endFrameNumber)setDebugOn()setDebugOn (Sprite s, int frameNumber)setDebugOff (Sprite s, int frameNumber)setDebugRange (Sprite s, int startFrameNumber, int endFrameNumber)initializeAnimation method
in any order. The only exceptions are that the order that Sprites are
added to the animation determine the order they are rendered in the
animation frame, and if two conflicting cues are given for any point
in time (ie set a sprite to be active and inactive in a certain
frame), the latter cue specified takes precedence.
RightBuggle choice
Add one Sprite to the animation.
import java.awt.*; // use colors
public class BuggleAnimation1 extends Animation {
public void initializeAnimation () {
RightBuggle s1 = new RightBuggle(Color.blue, 36, 0, 0, 2);
addSprite(s1, "s1");
}
}
RightLeftBuggle choice
import java.awt.*; // use colors
public class BuggleAnimation2 extends Animation {
public void initializeAnimation () {
setNumberFrames(100);
setFrameSize(400,120);
RightBuggle s1 = new RightBuggle(Color.blue, 36, 0, 0, 2);
RightLeftBuggle s2 = new RightLeftBuggle(Color.green, 48, 200, 50, -20);
addSprite(s1, "s1");
addSprite(s2, "s2");
}
}
SpyBuggle choice
import java.awt.*; // use colors
public class BuggleAnimation3 extends Animation {
public void initializeAnimation () {
setFps(20);
setNumberFrames(100);
setFrameSize(450,150);
RightBuggle s1 = new RightBuggle(Color.blue, 36, 0, 0, 2);
RightLeftBuggle s2 = new RightLeftBuggle(Color.green, 48, 200, 50, -20);
SpyBuggle s3 = new SpyBuggle(Color.yellow, 24, 400, 100, 25);
addSprite(s1, "s1");
addSprite(s2, "s2");
addSprite(s3, "s3");
}
}
SpyArmy choiceSprite s1 = new RightBuggle(...)
import java.awt.*; // use colors
public class BuggleAnimation4 extends Animation {
public void initializeAnimation () {
setFps(20);
setNumberFrames(100);
setFrameSize(400,350);
Sprite background = new ColorBackground(Color.gray);
addSprite(background, "background");
Sprite s1 = new RightBuggle(Color.blue, 36, 0, 0, 2);
Sprite s2 = new RightLeftBuggle(Color.green, 48, 200, 50, -20);
Sprite s3 = new SpyBuggle(Color.yellow, 24, 350, 100, 25);
Sprite s4 = new SpyArmy(3, Color.red, 60, 100, 130, 15);
addSprite(s1, "s1");
addSprite(s2, "s2");
addSprite(s3, "s3");
addSprite(s4, "s4");
}
}
SpyArmyII and SpyArmyIII choices
import java.awt.*; // use colors
public class BuggleAnimation5 extends Animation {
private Color c1; // color for background
private Color c2; // color for RightBuggle
private Color c3; // color for RightLeftBuggle
private Color c4; // color for SpyBuggle
private Color c5; // color for SpyArmy
public BuggleAnimation5 () {
this.c1 = Color.black;
this.c2 = Color.blue;
this.c3 = Color.green;
this.c4 = Color.yellow;
this.c5 = Color.red;
}
public BuggleAnimation5 (Color c1, Color c2, Color c3, Color c4, Color c5) {
this.c1 = c1;
this.c2 = c2;
this.c3 = c3;
this.c4 = c4;
this.c5 = c5;
}
public void initializeAnimation () {
setNumberFrames(100);
Sprite background = new ColorBackground(c1);
Sprite s1 = new RightBuggle(c2, 36, 0, 0, 2);
Sprite s2 = new RightLeftBuggle(c3, 48, 200, 50, -20);
Sprite s3 = new SpyBuggle(c4, 24, 400, 100, 25);
Sprite s4 = new SpyArmy(3, c5, 60, 100, 130, 15);
addSprite(background, "background");
addSprite(s1, "s1");
addSprite(s2, "s2");
addSprite(s3, "s3");
addSprite(s4, "s4");
}
}
BugglesInAndOut choice
import java.awt.*; // use colors
public class BuggleAnimation6 extends Animation {
public void initializeAnimation () {
// set properties of animation
setFps(15); // set frames per second
setNumberFrames(90); // set number of frames
// first background
Sprite background1 = new ColorBackground(Color.black);
addSprite(background1, "background1");
setHidden(background1,30);
// second background
Sprite background2 = new ColorBackground(Color.blue);
addSprite(background2, "background2");
setHidden(background2,1);
setActiveAndVisibleRange(background2,30,59);
// third background
Sprite background3 = new ColorBackground(Color.green);
addSprite(background3, "background3");
setHidden(background3,1);
setVisible(background3,60);
Sprite s1 = new SpyBuggle(Color.cyan, 50, 60, 150, 5);
addSprite(s1, "s1");
Sprite s2 = new SpyArmy(5, Color.magenta, 25, 150, 200, -20);
addSprite(s2, "s2");
setInactiveAndHiddenRange(s2,1,20);
setHidden(s2,80);
Sprite s3 = new SpyBuggle(Color.yellow, 40, 350, 20, -15);
addSprite(s3, "s3");
setHidden(s3,40);
setVisible(s3,60);
Sprite s4 = new SpyArmy(2, Color.red, 30, 100, 280, 25);
addSprite(s4, "s4");
setHidden(s4,25);
setVisible(s4,55);
}
}