mhframework.media
Class MHImageGroup

java.lang.Object
  extended by mhframework.media.MHImageGroup

public final class MHImageGroup
extends java.lang.Object

Maintains a complete set of animation sequences (MHFrameSequence objects) for a particular type of actor (MHActor).

Objects requiring groups of images can instantiate an MHImageGroup and use it for all sprite animation capabilities. Client classes are encouraged to keep their own sequence ID numbers, and are required to track their own sequences and frame numbers.

These classes are organized in a composition hierarchy like this:

How to use this system:

  1. Declare and instantiate an MHImageGroup object
  2. Call addSequence with a sequence ID number
  3. Call addFrame to add frames to a sequence


Constructor Summary
MHImageGroup()
          Constructor.
 
Method Summary
 void addFrame(int sequenceID, java.awt.Image newImage, int duration)
          Adds an animation frame to an existing frame sequence
 void addFrame(int sequenceID, java.lang.String imageFile, int duration)
          Adds an animation frame to an existing frame sequence.
 void addSequence(int sequenceID)
          Adds a new animation sequence to an image group.
 int getDuration(int sequenceID, int frameNumber)
          Returns the duration of the specified frame.
 int getFrameCount(int sequenceID)
          Returns the number of frames in the specified sequence.
 java.awt.Image getImage(int sequenceID, int frameNumber)
          Returns the requested image from the image group.
 int getNumSequences()
          Returns the number of animation sequences in this image group.
static java.awt.Image loadImage(java.lang.String imageFile)
           
 boolean sequenceExists(int sequenceID)
           
 void setDuration(int sequenceID, int frameNumber, int newDuration)
          Sets the duration of the specified frame.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MHImageGroup

public MHImageGroup()
Constructor.

Method Detail

addFrame

public void addFrame(int sequenceID,
                     java.lang.String imageFile,
                     int duration)
Adds an animation frame to an existing frame sequence.

Parameters:
sequenceID - The sequence to which the frame is to be added.
imageFile - The name of the image file containing the image to be used for the animation frame.
duration - The duration in loop iterations for which this frame is shown before advancing to the next frame.

loadImage

public static java.awt.Image loadImage(java.lang.String imageFile)

addFrame

public void addFrame(int sequenceID,
                     java.awt.Image newImage,
                     int duration)
Adds an animation frame to an existing frame sequence

Parameters:
sequenceID - The sequence to which the frame is to be added.
newImage - The image to be used for the animation frame.
duration - The duration in loop iterations for which this frame is shown before advancing to the next frame.

addSequence

public void addSequence(int sequenceID)
Adds a new animation sequence to an image group. If the requested ID for the new sequence is already in use, the old sequence is overwritten.

Parameters:
sequenceID - The number of the sequence to be added.

sequenceExists

public boolean sequenceExists(int sequenceID)

getImage

public java.awt.Image getImage(int sequenceID,
                               int frameNumber)
Returns the requested image from the image group.


getDuration

public int getDuration(int sequenceID,
                       int frameNumber)
Returns the duration of the specified frame.


setDuration

public void setDuration(int sequenceID,
                        int frameNumber,
                        int newDuration)
Sets the duration of the specified frame.


getFrameCount

public int getFrameCount(int sequenceID)
Returns the number of frames in the specified sequence.

Parameters:
sequenceID - The ID number of the sequence whose frame count is requested.
Returns:
The number of frames in the sequence.

getNumSequences

public int getNumSequences()
Returns the number of animation sequences in this image group.

Returns:
The total number of animation sequences in this image group.