org.newdawn.slick
Class Animation

java.lang.Object
  extended by org.newdawn.slick.Animation
All Implemented Interfaces:
Renderable

public class Animation
extends java.lang.Object
implements Renderable

A utility to hold and render animations

Author:
kevin, DeX (speed updates)

Constructor Summary
Animation()
          Create an empty animation
Animation(boolean autoUpdate)
          Create an empty animation
Animation(Image[] frames, int duration)
          Create a new animation from a set of images
Animation(Image[] frames, int[] durations)
          Create a new animation from a set of images
Animation(Image[] frames, int[] durations, boolean autoUpdate)
          Create a new animation from a set of images
Animation(Image[] frames, int duration, boolean autoUpdate)
          Create a new animation from a set of images
Animation(SpriteSheet frames, int duration)
          Create a new animation based on the sprite from a sheet.
Animation(SpriteSheet ss, int[] frames, int[] duration)
          Creates a new Animation where each frame is a sub-image of SpriteSheet ss.
Animation(SpriteSheet frames, int x1, int y1, int x2, int y2, boolean horizontalScan, int duration, boolean autoUpdate)
          Create a new animation based on a selection of sprites from a sheet
 
Method Summary
 void addFrame(Image frame, int duration)
          Add animation frame to the animation
 void addFrame(int duration, int x, int y)
          Add animation frame to the animation.
 Animation copy()
          Create a copy of this animation.
 void draw()
          Draw the animation to the screen
 void draw(float x, float y)
          Draw the animation at a specific location
 void draw(float x, float y, Color filter)
          Draw the animation at a specific location
 void draw(float x, float y, float width, float height)
          Draw the animation
 void draw(float x, float y, float width, float height, Color col)
          Draw the animation
 void drawFlash(float x, float y, float width, float height)
          Draw the animation
 void drawFlash(float x, float y, float width, float height, Color col)
          Draw the animation
 Image getCurrentFrame()
          Get the image associated with the current animation frame
 int getDuration(int index)
          Get the duration of a particular frame
 int[] getDurations()
          Get the durations of all the frames in this animation
 int getFrame()
          Get the index of the current frame
 int getFrameCount()
          Get the number of frames that are in the animation
 int getHeight()
          Get the height of the current frame
 Image getImage(int index)
          Get the image assocaited with a given frame index
 float getSpeed()
          Returns the current speed of the animation.
 int getWidth()
          Get the width of the current frame
 boolean isStopped()
          Check if this animation has stopped (either explictly or because it's reached its target frame)
 void renderInUse(int x, int y)
          Render the appropriate frame when the spriteSheet backing this Animation is in use.
 void restart()
          Restart the animation from the beginning
 void setAutoUpdate(boolean auto)
          Indicate if this animation should automatically update based on the time between renders or if it should need updating via the update() method.
 void setCurrentFrame(int index)
          Set the current frame to be rendered
 void setDuration(int index, int duration)
          Set the duration of the given frame
 void setLooping(boolean loop)
          Indicate if this animation should loop or stop at the last frame
 void setPingPong(boolean pingPong)
          Indicate if this animation should ping pong back and forth
 void setSpeed(float spd)
          Adjust the overall speed of the animation.
 void start()
          Start the animation playing again
 void stop()
          Stop the animation
 void stopAt(int frameIndex)
          Indicate the animation should stop when it reaches the specified frame index (note, not frame number but index in the animation
 java.lang.String toString()
           
 void update(long delta)
          Update the animation, note that this will have odd effects if auto update is also turned on
 void updateNoDraw()
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Animation

public Animation()
Create an empty animation


Animation

public Animation(Image[] frames,
                 int duration)
Create a new animation from a set of images

Parameters:
frames - The images for the animation frames
duration - The duration to show each frame

Animation

public Animation(Image[] frames,
                 int[] durations)
Create a new animation from a set of images

Parameters:
frames - The images for the animation frames
durations - The duration to show each frame

Animation

public Animation(boolean autoUpdate)
Create an empty animation

Parameters:
autoUpdate - True if this animation should automatically update. This means that the current frame will be caculated based on the time between renders

Animation

public Animation(Image[] frames,
                 int duration,
                 boolean autoUpdate)
Create a new animation from a set of images

Parameters:
frames - The images for the animation frames
duration - The duration to show each frame
autoUpdate - True if this animation should automatically update. This means that the current frame will be caculated based on the time between renders

Animation

public Animation(Image[] frames,
                 int[] durations,
                 boolean autoUpdate)
Create a new animation from a set of images

Parameters:
frames - The images for the animation frames
durations - The duration to show each frame
autoUpdate - True if this animation should automatically update. This means that the current frame will be caculated based on the time between renders

Animation

public Animation(SpriteSheet frames,
                 int duration)
Create a new animation based on the sprite from a sheet. It assumed that the sprites are organised on horizontal scan lines and that every sprite in the sheet should be used.

Parameters:
frames - The sprite sheet containing the frames
duration - The duration each frame should be displayed for

Animation

public Animation(SpriteSheet frames,
                 int x1,
                 int y1,
                 int x2,
                 int y2,
                 boolean horizontalScan,
                 int duration,
                 boolean autoUpdate)
Create a new animation based on a selection of sprites from a sheet

Parameters:
frames - The sprite sheet containing the frames
x1 - The x coordinate of the first sprite from the sheet to appear in the animation
y1 - The y coordinate of the first sprite from the sheet to appear in the animation
x2 - The x coordinate of the last sprite from the sheet to appear in the animation
y2 - The y coordinate of the last sprite from the sheet to appear in the animation
horizontalScan - True if the sprites are arranged in hoizontal scan lines. Otherwise vertical is assumed
duration - The duration each frame should be displayed for
autoUpdate - True if this animation should automatically update based on the render times

Animation

public Animation(SpriteSheet ss,
                 int[] frames,
                 int[] duration)
Creates a new Animation where each frame is a sub-image of SpriteSheet ss.

Parameters:
ss - The SpriteSheet backing this animation
frames - An array of coordinates of sub-image locations for each frame
duration - The duration each frame should be displayed for
Method Detail

addFrame

public void addFrame(int duration,
                     int x,
                     int y)
Add animation frame to the animation.

Parameters:
duration - The duration to display the frame for
x - The x location of the frame on the SpriteSheet
y - The y location of the frame on the spriteSheet

setAutoUpdate

public void setAutoUpdate(boolean auto)
Indicate if this animation should automatically update based on the time between renders or if it should need updating via the update() method.

Parameters:
auto - True if this animation should automatically update

setPingPong

public void setPingPong(boolean pingPong)
Indicate if this animation should ping pong back and forth

Parameters:
pingPong - True if the animation should ping pong

isStopped

public boolean isStopped()
Check if this animation has stopped (either explictly or because it's reached its target frame)

Returns:
True if the animation has stopped
See Also:
stopAt

setSpeed

public void setSpeed(float spd)
Adjust the overall speed of the animation.

Parameters:
spd - The speed to run the animation. Default: 1.0

getSpeed

public float getSpeed()
Returns the current speed of the animation.

Returns:
The speed this animation is being played back at

stop

public void stop()
Stop the animation


start

public void start()
Start the animation playing again


restart

public void restart()
Restart the animation from the beginning


addFrame

public void addFrame(Image frame,
                     int duration)
Add animation frame to the animation

Parameters:
frame - The image to display for the frame
duration - The duration to display the frame for

draw

public void draw()
Draw the animation to the screen


draw

public void draw(float x,
                 float y)
Draw the animation at a specific location

Specified by:
draw in interface Renderable
Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at

draw

public void draw(float x,
                 float y,
                 Color filter)
Draw the animation at a specific location

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at
filter - The filter to apply

draw

public void draw(float x,
                 float y,
                 float width,
                 float height)
Draw the animation

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at
width - The width to draw the animation at
height - The height to draw the animation at

draw

public void draw(float x,
                 float y,
                 float width,
                 float height,
                 Color col)
Draw the animation

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at
width - The width to draw the animation at
height - The height to draw the animation at
col - The colour filter to use

renderInUse

public void renderInUse(int x,
                        int y)
Render the appropriate frame when the spriteSheet backing this Animation is in use.

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at

getWidth

public int getWidth()
Get the width of the current frame

Returns:
The width of the current frame

getHeight

public int getHeight()
Get the height of the current frame

Returns:
The height of the current frame

drawFlash

public void drawFlash(float x,
                      float y,
                      float width,
                      float height)
Draw the animation

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at
width - The width to draw the animation at
height - The height to draw the animation at

drawFlash

public void drawFlash(float x,
                      float y,
                      float width,
                      float height,
                      Color col)
Draw the animation

Parameters:
x - The x position to draw the animation at
y - The y position to draw the animation at
width - The width to draw the animation at
height - The height to draw the animation at
col - The colour for the flash

updateNoDraw

public void updateNoDraw()
Deprecated. 

Update the animation cycle without draw the image, useful for keeping two animations in sync


update

public void update(long delta)
Update the animation, note that this will have odd effects if auto update is also turned on

Parameters:
delta - The amount of time thats passed since last update
See Also:
autoUpdate

getFrame

public int getFrame()
Get the index of the current frame

Returns:
The index of the current frame

setCurrentFrame

public void setCurrentFrame(int index)
Set the current frame to be rendered

Parameters:
index - The index of the frame to rendered

getImage

public Image getImage(int index)
Get the image assocaited with a given frame index

Parameters:
index - The index of the frame image to retrieve
Returns:
The image of the specified animation frame

getFrameCount

public int getFrameCount()
Get the number of frames that are in the animation

Returns:
The number of frames that are in the animation

getCurrentFrame

public Image getCurrentFrame()
Get the image associated with the current animation frame

Returns:
The image associated with the current animation frame

setLooping

public void setLooping(boolean loop)
Indicate if this animation should loop or stop at the last frame

Parameters:
loop - True if this animation should loop (true = default)

stopAt

public void stopAt(int frameIndex)
Indicate the animation should stop when it reaches the specified frame index (note, not frame number but index in the animation

Parameters:
frameIndex - The index of the frame to stop at

getDuration

public int getDuration(int index)
Get the duration of a particular frame

Parameters:
index - The index of the given frame
Returns:
The duration in (ms) of the given frame

setDuration

public void setDuration(int index,
                        int duration)
Set the duration of the given frame

Parameters:
index - The index of the given frame
duration - The duration in (ms) for the given frame

getDurations

public int[] getDurations()
Get the durations of all the frames in this animation

Returns:
The durations of all the frames in this animation

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

copy

public Animation copy()
Create a copy of this animation. Note that the frames are not duplicated but shared with the original

Returns:
A copy of this animation


Copyright © 2006 New Dawn Software. All Rights Reserved.