To play our animations, we just extend a preexisting AnimationPlayer implementation. Two animation players are currently available.
- SimpleAnimationPlayer This AnimationPlayer allows users to add one animation and play it.
- AnimationShowcase This AnimationPlayer is an extension of the SimpleAnimationPlayer and allows users to add multiple animations and to switch between the animations. Users may switch between animations when an animation is running. Animations which are selected always start from their first frame.
- RESET Puts the animation in its initial state. Stops the animation if it is running.
- PLAY Plays the animation. Does nothing if animation is already running.
- STOP Stops the animation. Does nothing if animation is not playing.
- NEXT Advances to next animation frame. Does nothing if animation is running.
- GOTO Advances to frame number entered in the textfield. Does nothing if animation is running.
To create an Animation Player for our animation, we extend one of the two
players above, and implement a default constructor method. In the constructor we
create an instance of our animations and add them to the player via the
addAnimation(String name, Animation a)
method.
The SimpleAnimationPlayer will ignore all animations added but the first
one. The choice list for the AnimationShowcase will be in the order that
animations are added to the player. The name is required and is displayed
in the interface.
The following methods may also be used to configure the appearance of the animation player. All methods are available for both players.
setScreenColor(Color c)
Sets the screen color to the color specified.hideResetButton()
Hides the RESET button.hidePlayButton()
Hides the PLAY button.hideStopButton()
Hides the STOP button.hideNextButton()
Hides the NEXT button.hideGotoButton()
Hides the GOTO button.hideFrameNumberDisplay()
Note that this method will not work unless the GOTO button has been hidden first.hideControlPanel()
Hides all the the buttons and labels so only the animation shows.
The following methods may be used to configure when the animation plays automatically. By default, animations are not played until users hit the PLAY button. Animations automatically stop when the user leaves the web page (goes to another web page) or when the web browser window loses focus.
setPlayOnStart()
Animations will play every time the applet is started in the web browser. This typically occurs every time the user loads the web page into the web browser.setPlayOnPaint()
Animations will play every time the applet is "painted". This occurs every time the web browser gains focus or when the user scrolls so that the applet appears on the page again.setPlayOnSelection()
AnimationShowcase only
Animations will play each time a new animation is selected to be the current selection. The first animation is also played when the applet is first loaded.
Examples
The example code demonstrates most of the features above. Clicking on the link will open up a new web browser window with the player so you can see what the player looks like. Each player below would be defined in its own file named after the name of the animation player class.
BuggleAnimationPlayer1
Extending the SimpleAnimationPlayer
public class BuggleAnimationPlayer1 extends SimpleAnimationPlayer { public BuggleAnimationPlayer1 () { addAnimation("RightBuggle", new BuggleAnimation1()); } }BuggleAnimationPlayer2
Extending the SimpleAnimationPlayer again. Can put any animation in the player with any name.
public class BuggleAnimationPlayer2 extends SimpleAnimationPlayer { public BuggleAnimationPlayer2 () { addAnimation("RightLeftBuggle", new BuggleAnimation2()); } }BuggleAnimationPlayer3
Setting the animation player to play the animation every time the web page is loaded.
public class BuggleAnimationPlayer3 extends SimpleAnimationPlayer { public BuggleAnimationPlayer3 () { setPlayOnStart(); addAnimation("SpyBuggle", new BuggleAnimation3()); } }BuggleAnimationPlayer4
Setting the animation player to play the animation every time the applet is painted. Set the screen color.
public class BuggleAnimationPlayer4 extends SimpleAnimationPlayer { public BuggleAnimationPlayer4 () { setScreenColor(new Color(128,0,0)); // maroon setPlayOnPaint(); addAnimation("SpyArmy", new BuggleAnimation4()); } }BuggleAnimationPlayer5
Placing animation on page with no buttons or labels. Animation is played each time the web page is loaded.
public class BuggleAnimationPlayer5 extends SimpleAnimationPlayer { public BuggleAnimationPlayer5 () { hideControlPanel(); setPlayOnStart(); addAnimation("SpyArmyII", new BuggleAnimation5()); } }BuggleAnimationPlayer6
Placing animation on page with no buttons or labels. Animation is played each time web browser window gets focus or user scrolls to show applet.
import java.awt.*; // use colors public class BuggleAnimationPlayer6 extends SimpleAnimationPlayer { public BuggleAnimationPlayer6 () { hideControlPanel(); setPlayOnPaint(); addAnimation("SpyArmyIII", new BuggleAnimation5(Color.green, Color.blue, Color.red, Color.cyan, Color.magenta)); } }BugglesInAndOut
Extension of SimpleAnimationPlayer with only three buttons: RESET, PLAY, and STOP.
public class BugglesInAndOut extends SimpleAnimationPlayer { public BugglesInAndOut () { hideNextButton(); hideGotoButton(); hideFrameNumberDisplay(); addAnimation("BugglesInAndOut", new BuggleAnimation6()); } }BuggleShowcase
Extension of AnimationShowcase with all the animations above. Animations are set to play when selected.
import java.awt.*; // use colors public class BuggleShowcase extends AnimationShowcase { public BuggleShowcase () { setPlayOnSelection(); addAnimation("RightBuggle", new BuggleAnimation1()); addAnimation("RightLeftBuggle", new BuggleAnimation2()); addAnimation("SpyBuggle", new BuggleAnimation3()); addAnimation("SpyArmy", new BuggleAnimation4()); addAnimation("SpyArmyII", new BuggleAnimation5()); addAnimation("SpyArmyIII", new BuggleAnimation5(Color.green, Color.blue, Color.red, Color.cyan, Color.magenta)); addAnimation("Buggles In and Out", new BuggleAnimation6()); } }
AnimationWorld
Sprites
Animations
Animation Players