hermes.animation
Class AnimatedSprite

java.lang.Object
  extended by hermes.animation.AnimatedSprite
All Implemented Interfaces:
AnimationConstants

public class AnimatedSprite
extends java.lang.Object
implements AnimationConstants

This class is used to process, store, and play animations.


Field Summary
 
Fields inherited from interface hermes.animation.AnimationConstants
INFINITE_LOOPS
 
Constructor Summary
AnimatedSprite()
           
 
Method Summary
 int addAnimation(Animation animation)
           
 PImage animate()
          This method handles advancing the Animation's frame, and then returns the PImage corresponding to the Animation's current state
 Animation getAnimation(int index)
          Retrieves an Animation stored with this AnimatedSprite
 int getInitialFrame()
           
 int getLastFrame()
           
 int getNumberOfAnimations()
          the number of Animations added to this AnimatedSprite
 int getPlayDirection()
           
 boolean isPlayDirectionLeftToRight()
           
 void overrideInterruptible(boolean interruptible)
          Overrides interruptible -- valid until next call to setActiveAnimation.
 void overrideMillisecondsPerFrame(int millisecondsPerFrame)
          Overrides millisecondsPerFrame for this playback.
 void overrideNumberOfTimesToPlay(int numberOfTimesToPlay)
          Overrides millisecondsPerFrame -- valid until next call to setActiveAnimation.
 void pause()
          This pauses the Animated Sprite on its currentFrame.
 void reverse()
          This switches the direction of the playback and swaps the initial and final frames.
 void setActiveAnimation(int animationIndex)
          Sets the active animation that the Sprite will use when drawn
 void setInitialFrame(int initialFrame)
          Sets the initial frame for this playback.
 void setLastFrame(int lastFrame)
          Sets the last frame for this playback.
 void setPlayDirection(int direction)
          Sets the direction of play.
 void unpause()
          This tells the Animated Sprite to play its activeAnimation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimatedSprite

public AnimatedSprite()
Method Detail

addAnimation

public int addAnimation(Animation animation)

setActiveAnimation

public void setActiveAnimation(int animationIndex)
Sets the active animation that the Sprite will use when drawn

Note: This uses parameters internal to the specified animation for : millisecondsPerFrame, interruptible, isLooping, numberOfLoops. If you want to override any of these temporarily (ie: just for this playback, this does not change the Animation's internal parameters) use the override methods described in this class following your call to this method. Eg.

setActiveAnimation(3);
overrideInterruptible(true); //allows this playback to be interrupted


overrideNumberOfTimesToPlay(3);//will play through the Animation 3 times

Parameters:
animationIndex - numerical index used to select a specific animation of a sprite

overrideInterruptible

public void overrideInterruptible(boolean interruptible)
Overrides interruptible -- valid until next call to setActiveAnimation.
Note: this does not overwrite the Animation's internal interruptible

Parameters:
interruptible - boolean determining if this AnimatedSprite should be interruptible

overrideNumberOfTimesToPlay

public void overrideNumberOfTimesToPlay(int numberOfTimesToPlay)
Overrides millisecondsPerFrame -- valid until next call to setActiveAnimation.
Note: this does not overwrite the Animation's internal millisecondsPerFrame

Parameters:
numberOfTimesToPlay - Number of times this animation should play

getAnimation

public Animation getAnimation(int index)
Retrieves an Animation stored with this AnimatedSprite

Parameters:
index - The index of the animation being retrieved
Returns:
Animation stored with this AnimatedSprite

getNumberOfAnimations

public int getNumberOfAnimations()
the number of Animations added to this AnimatedSprite

Returns:
the number of Animations added to this AnimatedSprite

overrideMillisecondsPerFrame

public void overrideMillisecondsPerFrame(int millisecondsPerFrame)
Overrides millisecondsPerFrame for this playback. It is valid until the next call to setActiveAnimation.
Note: this does not overwrite the Animation's internal millisecondsPerFrame

Parameters:
millisecondsPerFrame - How many milliseconds each Animation frame will play for

getInitialFrame

public int getInitialFrame()
Returns:
the index of the initial frame of the Animation

setInitialFrame

public void setInitialFrame(int initialFrame)
Sets the initial frame for this playback. It is basically the loop's head marker. A single play of the Animation will start at the initial frame, and play each frame in the direction specified by playDirectionLeftToRight() or playDirectionRightToLeft() until the last frame is reached. If the Animation must loop again, it will start the process over again at the initial frame.
Note: by default this is set to 0, the index of the leftmost frame from the Animation

Parameters:
initialFrame - the index of the initial frame in the Animation

getLastFrame

public int getLastFrame()
Returns:
the index of the last frame of the Animation

setLastFrame

public void setLastFrame(int lastFrame)
Sets the last frame for this playback. It is basically the loop's end marker. A single play of the Animation will start at the initial frame, and play each frame in the direction specified by playDirectionLeftToRight() or playDirectionRightToLeft() until the last frame is reached. If the Animation must loop again, it will start the process over again at the initial frame.
Note: by default this is set to the (number of frames in the Animation - 1), the rightmost frame

Parameters:
lastFrame - the index of the last frame in the Animation

setPlayDirection

public void setPlayDirection(int direction)
Sets the direction of play. Use "1" for left-to-right, and "-1" for right-to-left.
Eg. if the Animation sequence is A-B-C-D-E, and direction argument is given a -1,the frames will play in the following order: E,D,C,B,A

Parameters:
direction - Number used to determine direction of playback. "1" for left-to-right, and "-1" for right-to-left

isPlayDirectionLeftToRight

public boolean isPlayDirectionLeftToRight()
Returns:
true if the play direction is left to right, false if the play direction is right to left

getPlayDirection

public int getPlayDirection()
Returns:
1 if the play direction is right to left, -1 if the play direction is left to right

unpause

public void unpause()
This tells the Animated Sprite to play its activeAnimation. It may be used after a call to pause() to restart the play.


pause

public void pause()
This pauses the Animated Sprite on its currentFrame. It respects the setting of Interruptible.


animate

public PImage animate()
This method handles advancing the Animation's frame, and then returns the PImage corresponding to the Animation's current state


reverse

public void reverse()
This switches the direction of the playback and swaps the initial and final frames. Eg. if the frames play A-B-C, then you call reverse(), they will play C-B-A. If the Animation is interruptible, the reverse will happen immediately. If the Animation is not interruptible, the changes will be come into effect when the Animation has been played through. These changes are only relevant while this is the active Animation and they are valid for this playback.