hermes.animation
Class Animation

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

public class Animation
extends java.lang.Object
implements AnimationConstants

This class is used to store the PImages that make up a single animation and some properties that aid in playing that animation. These properties values should be thought of as "default" for this particular Animation, values that you know will work well or be used the most often.

The key properties are:


Field Summary
 
Fields inherited from interface hermes.animation.AnimationConstants
INFINITE_LOOPS
 
Constructor Summary
Animation(java.util.ArrayList<PImage> someArrayListOfPImages, int millisecondsPerFrame)
          Builds a new Animation from an ArrayList of PImages and adds it to the Sprite's collection of Animations
Animation(PImage[] someArrayOfPImages, int millisecondsPerFrame)
          Builds a new Animation from a PImage[] and adds it to the Sprite's collection of Animations
Animation(java.lang.String imageSequenceNamePrefix, int startIndex, int endIndex, java.lang.String fileType, int millisecondsPerFrame)
          Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations
Animation(java.lang.String imageSequenceNamePrefix, int numberOfImagesToLoad, java.lang.String fileType, int millisecondsPerFrame)
          Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations
 
Method Summary
 int getDefaultFrame()
           
 PImage getFrame(int index)
           
 boolean getInterruptible()
           
 int getMillisecondsPerFrame()
           
 int getNumberOfFrames()
           
 int getNumberOfTimesToPlay()
           
 void setDefaultFrame(int indexOfDefaultFrame)
           
 void setInterruptible(boolean interruptible)
          This is used to determine what happens when an AnimatedSprite's setActiveAnimation is called while this Animation is playing.
 void setMillisecondsPerFrame(int millisecondsPerFrame)
          Sets how many milliseconds each Animation frame will play for
Note: if you only want to change this value for one call to AnimatedSprite's setActiveAnimation, use the overrideMillisecondsPerFrame() method in the AnimatedSprite class.
 void setNumberOfTimesToPlay(int numberOfTimesToPlay)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Animation

public Animation(java.lang.String imageSequenceNamePrefix,
                 int numberOfImagesToLoad,
                 java.lang.String fileType,
                 int millisecondsPerFrame)
Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations

The method loads files with numbers starting from 0 to (numberOfImagesToLoad-1) and assumes numerical contiguity
ex. Explosion0.jpg, Explosion1.jpg, Explosion2.jpg would have method call:
addAnimationFromSequenceOfImages("Explosion", 3, ".jpg");

Works with all image filetypes supported by PImage: .gif, .jgp, tga, .png

Parameters:
imageSequenceNamePrefix - file prefix of all of the images to be loaded into this Animation ex. "Explosion"
numberOfImagesToLoad - total number of images to load (note: your names should be indexed starting from 0)
fileType - file extension including the 'dot' - supports: ".gif" ".jgp" ".tga" ".png"
millisecondsPerFrame - amount of time each frame in the Animation is displayed, in milliseconds

Animation

public Animation(java.lang.String imageSequenceNamePrefix,
                 int startIndex,
                 int endIndex,
                 java.lang.String fileType,
                 int millisecondsPerFrame)
Builds an Animation from several image files on disk (where each is an individual frame in the Animation), and adds it to the Sprite's collection of Animations

The method loads files within the specified number range and assumes numerical contiguity
ex. Explosion1.jpg, Explosion2.jpg, Explosion3.jpg would have method call:
addAnimationFromSequenceOfImages("Explosion", 1, 3, ".jpg");

Works with all image filetypes supported by PImage: .gif, .jgp, tga, .png

Parameters:
imageSequenceNamePrefix - file prefix of all of the images to be loaded into this Animation ex. "Explosion"
startIndex - starting index to load from
endIndex - ending index to load from
fileType - file extension including the 'dot' - supports: ".gif" ".jgp" ".tga" ".png"
millisecondsPerFrame - amount of time each frame in the Animation is displayed, in milliseconds

Animation

public Animation(java.util.ArrayList<PImage> someArrayListOfPImages,
                 int millisecondsPerFrame)
Builds a new Animation from an ArrayList of PImages and adds it to the Sprite's collection of Animations

Parameters:
someArrayListOfPImages - an ArrayList of PImages you'd like to use as an Animation for a sprite
millisecondsPerFrame - amount of time each frame in the Animation is displayed

Animation

public Animation(PImage[] someArrayOfPImages,
                 int millisecondsPerFrame)
Builds a new Animation from a PImage[] and adds it to the Sprite's collection of Animations

Parameters:
someArrayOfPImages - a PImage[] you'd like to use as an Animation for a sprite
millisecondsPerFrame - amount of time each frame in the Animation is displayed
Method Detail

getNumberOfFrames

public int getNumberOfFrames()
Returns:
Number of frames contained in the Animation (ie: the Animations' length in frames)

getFrame

public PImage getFrame(int index)
Parameters:
index - The index of the frame you'd like to retrieve
Returns:
The PImage frame at the index

getMillisecondsPerFrame

public int getMillisecondsPerFrame()
Returns:
How many milliseconds each Animation frame will play for

setMillisecondsPerFrame

public void setMillisecondsPerFrame(int millisecondsPerFrame)
Sets how many milliseconds each Animation frame will play for
Note: if you only want to change this value for one call to AnimatedSprite's setActiveAnimation, use the overrideMillisecondsPerFrame() method in the AnimatedSprite class.


getInterruptible

public boolean getInterruptible()
Returns:
True if interruptible, false otherwise

setInterruptible

public void setInterruptible(boolean interruptible)
This is used to determine what happens when an AnimatedSprite's setActiveAnimation is called while this Animation is playing.

If set to true (default), the AnimatedSprite will immediately switch to the new Animation.

If set to false, this Animation will play to completion before changing (If it is looping, it will play to the end of the Animation. If it isn't looping, the Animation will play through the remaining cycles it has left).
Upon completion of uninterrupted playback, there are two cases:

Parameters:
interruptible - boolean to specify if Animation should be interruptible

getNumberOfTimesToPlay

public int getNumberOfTimesToPlay()
Returns:
The number of times this is set to play.

setNumberOfTimesToPlay

public void setNumberOfTimesToPlay(int numberOfTimesToPlay)
Parameters:
numberOfTimesToPlay - the number of times this animation is set to play through all its frames Note: use INFINITE_LOOPS to set animation to loop infinitely

getDefaultFrame

public int getDefaultFrame()
Returns:
the index of the default frame

setDefaultFrame

public void setDefaultFrame(int indexOfDefaultFrame)
Parameters:
indexOfDefaultFrame - the index of the default frame