net.jinx.video
Class Animation

java.lang.Object
  extended by net.jinx.video.Animation
All Implemented Interfaces:
MultipassVisible, Visible

public class Animation
extends java.lang.Object
implements MultipassVisible

Allows multiple Visibles to be used based on time in an animation sequence. The animation has a duration and a series of frames, each of which is another Visible. The duration is used to determine how often the animation should repeat.
Once start() is called, animation begins. When the draw() method is called, the current frame is determined. This is done by first calculating the time in milliseconds that has passed since start() was last called. This is then divided by the duration. The remainder of that division is the current time within the animation. This determines the current frame, since each frame has a time value associated with it (the time value for a frame that is less than or equal to the current time within the animation is used).
If there is no frame that fits the above, then nothing will be displayed.

API Stability: Stable.


Constructor Summary
Animation()
          Constructs an Animation object with a default duration of 1 millisecond.
 
Method Summary
 void addFrame(long time, Visible drawable)
          Adds a frame to the animation that will be used after the given time value.
 void deinit(Context opt)
          Deinitializes this Animation's frames.
 void draw(Context opt)
          Draws the current frame of the Animation; implies a call to start().
 void drawPass(Context opt, Pass pass)
           
 long firstFrame()
          Utility method to return the first frame's time value.
 void init(Context opt)
          Initializes this Animation's frames.
 void setDuration(long duration)
          Sets the duration (in milliseconds) of the animation.
 void start()
          Starts the animation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Animation

public Animation()
Constructs an Animation object with a default duration of 1 millisecond.

Method Detail

setDuration

public void setDuration(long duration)
Sets the duration (in milliseconds) of the animation.

Parameters:
duration - a long value for the duration.
Throws:
java.lang.IllegalArgumentException - if the duration is less than or equal to zero.

addFrame

public void addFrame(long time,
                     Visible drawable)
Adds a frame to the animation that will be used after the given time value.

Parameters:
time - the time in milliseconds after which the frame will be used.
drawable - the Visible will be used as the frame.
Throws:
java.lang.NullPointerException - if drawable is null.

firstFrame

public long firstFrame()
Utility method to return the first frame's time value.

Returns:
the time in milliseconds after which the first frame will be used.

start

public void start()
Starts the animation. All time values will be calculated from the time this method is called. init(Context) must have been called first.

Throws:
java.lang.NullPointerException - if init hasn't been called.

init

public void init(Context opt)
Initializes this Animation's frames.

Specified by:
init in interface Visible
Parameters:
opt - describes the rendering options that are being used.

deinit

public void deinit(Context opt)
Deinitializes this Animation's frames.

Specified by:
deinit in interface Visible
Parameters:
opt - describes the rendering options that are being used.

draw

public void draw(Context opt)
Draws the current frame of the Animation; implies a call to start(). See Visible.draw() for more information.

Specified by:
draw in interface Visible
Parameters:
opt - describes the rendering options that are being used.

drawPass

public void drawPass(Context opt,
                     Pass pass)
Specified by:
drawPass in interface MultipassVisible