com.jpemartin.jgt
Class DrawAnim

java.lang.Object
  extended by com.jpemartin.jgt.DrawAnim
All Implemented Interfaces:
Drawable, java.lang.Cloneable

public class DrawAnim
extends java.lang.Object
implements Drawable, java.lang.Cloneable

Loads images, then displays an animation by looping through the images. The image can be in any format that Java can load; I recommend png. The loading will work for files on disk, a jar file, or files on a web server running an applet. Use relative names like "player.png" or "images/laser.png", not "c:\program files\java\my images\cool picture.png" If you have several objects using the same animation, it is more efficient to create one DrawAnim and then clone() it rather than creating several: the clone shares data with the original so you save on memory, and the images are loaded only once so you save on initialization time.

Author:
jpmartin

Constructor Summary
DrawAnim(java.util.Collection imageNames, int delay)
          An animation that loops through the given images, each image is displayed "delay" times (or once if delay<1).
DrawAnim(java.util.Collection imageNames, int delay, boolean keyed)
          An animation that loops through the given images, each image is displayed "delay" times (or once if delay<1).
DrawAnim(java.lang.String imageName)
          An animation that displays the given image.
DrawAnim(java.lang.String imageName, boolean keyed)
          An animation that displays the given image.
 
Method Summary
 java.lang.Object clone()
          creates a clone of this object.
 void draw(java.awt.Graphics g, int x, int y)
          draw one frame of the animation at the specified position
 int getHeight()
           
 int getLoopCount()
          return the number of times every frame in the animation was drawn
 int getWidth()
           
 void reset()
          back to original state (images loaded, beginning of anim loop).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DrawAnim

public DrawAnim(java.lang.String imageName)
         throws java.io.IOException
An animation that displays the given image.

Throws:
java.io.IOException

DrawAnim

public DrawAnim(java.lang.String imageName,
                boolean keyed)
         throws java.io.IOException
An animation that displays the given image. If keyed==true, all pixels that are the same color as the top-left pixel will be made transparent.

Throws:
java.io.IOException

DrawAnim

public DrawAnim(java.util.Collection imageNames,
                int delay)
         throws java.io.IOException
An animation that loops through the given images, each image is displayed "delay" times (or once if delay<1).

Throws:
java.io.IOException

DrawAnim

public DrawAnim(java.util.Collection imageNames,
                int delay,
                boolean keyed)
         throws java.io.IOException
An animation that loops through the given images, each image is displayed "delay" times (or once if delay<1). If keyed==true, all pixels that are the same color as the top-left pixel will be made transparent.

Throws:
java.io.IOException
Method Detail

reset

public void reset()
back to original state (images loaded, beginning of anim loop).


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
creates a clone of this object. The exception will never be thrown by this class.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y)
draw one frame of the animation at the specified position

Specified by:
draw in interface Drawable

getWidth

public int getWidth()

getHeight

public int getHeight()

getLoopCount

public int getLoopCount()
return the number of times every frame in the animation was drawn