PulpCore

pulpcore.animation
Class Animation

java.lang.Object
  extended by pulpcore.animation.Animation
Direct Known Subclasses:
Timeline, TimelineEvent, Tween

public abstract class Animation
extends Object

An Animation changes state over a specific duration. It is up to subclasses to implement the updateState(int) method to change the state as the Animation is updated over time. An Animation is updated over time with its update(int) method, which is typically called by a Timeline or, in the case of a Tween, by the Property it is attached to.

A simple Animation starts immediately:

    |===================|
    0     duration     end

    ------- time ------->
    

Animations can delay before they start:

    |--------------|===================|
    0  startDelay        duration     end

    ---------------- time --------------->
    

Animations can loop:

    |--------------|===================|===================|===================|
    0  startDelay        duration            duration           duration      end

    ----------------------------------- time ------------------------------------>
    

Animations can have a delay between loops:

    |--------------|================|------|================|------|================|
    0  startDelay       duration      loop      duration      loop      duration   end
                                      delay                   delay
    ------------------------------------- time ------------------------------------->
    

Also, Animations can have an Easing to make the Animation look more smooth.


Field Summary
static int LOOP_FOREVER
          Value indicating that the Animation loops forever.
 
Constructor Summary
Animation(int duration)
           
Animation(int duration, Easing easing)
           
Animation(int duration, Easing easing, int startDelay)
           
 
Method Summary
 void fastForward()
          Sets the current time to the end of this animation.
 int getDuration()
           
 Easing getEasing()
           
 int getLoopDelay()
           
 int getNumLoops()
           
 int getStartDelay()
           
 int getTime()
           
 int getTotalDuration()
          Returns the total duration including the start delay and loops.
 boolean isFinished()
           
 void loop(int numLoops)
          Sets the number of loops to play.
 void loop(int numLoops, int loopDelay)
          Sets the number of loops to play.
 void loopForever()
          Causes this animation to loop indefinitely.
 void loopForever(int loopDelay)
          Causes this animation to loop indefinitely.
 void rewind()
           
 boolean update(int elapsedTime)
           
protected abstract  void updateState(int animTime)
          Updates the state based on the animation time, typically from 0 to getDuration().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOOP_FOREVER

public static final int LOOP_FOREVER
Value indicating that the Animation loops forever.

See Also:
loopForever(), getTotalDuration(), Constant Field Values
Constructor Detail

Animation

public Animation(int duration)

Animation

public Animation(int duration,
                 Easing easing)

Animation

public Animation(int duration,
                 Easing easing,
                 int startDelay)
Method Detail

loopForever

public final void loopForever()
Causes this animation to loop indefinitely. Same as loop(LOOP_FOREVER, 0).

If the duration is 0 this call is ignored.

Throws:
IllegalArgumentException - if duration is 0

loopForever

public final void loopForever(int loopDelay)
Causes this animation to loop indefinitely. Same as loop(LOOP_FOREVER, loopDelay).

If the duration is 0 and loopDelay is 0, this call is ignored.

Parameters:
loopDelay - The delay between the end of a duration and the start of a new one.
Throws:
IllegalArgumentException - if loopDelay is negative.
IllegalArgumentException - if duration is 0 and loopDelay is 0.

loop

public final void loop(int numLoops)
Sets the number of loops to play. A value of LOOP_FOREVER causes this timeline to play indefinitely.

If looping (numLoops != 1), and the duration is 0, this call is ignored.

Parameters:
numLoops - The number of times to loop the duration. A value of 1 means the duration is played exactly once.
Throws:
IllegalArgumentException - if numLoops is not LOOP_FOREVER but is < 1.

loop

public final void loop(int numLoops,
                       int loopDelay)
Sets the number of loops to play. A value of LOOP_FOREVER causes this timeline to play indefinitely.

If looping (numLoops != 1), and the duration is 0, and loopDelay is 0, this call is ignored.

Parameters:
numLoops - The number of times to loop the duration. A value of 1 means the duration is played exactly once.
loopDelay - The delay between the end of one duration and the start of the next one.
Throws:
IllegalArgumentException - if numLoops is not LOOP_FOREVER but is < 1.
IllegalArgumentException - if loopDelay is negative.
IllegalArgumentException - if looping (numLoops != 1), duration is 0, and loopDelay is 0.

getStartDelay

public final int getStartDelay()

getDuration

public final int getDuration()

getEasing

public final Easing getEasing()

getNumLoops

public final int getNumLoops()

getLoopDelay

public final int getLoopDelay()

getTotalDuration

public final int getTotalDuration()
Returns the total duration including the start delay and loops.


getTime

public final int getTime()

isFinished

public final boolean isFinished()

fastForward

public final void fastForward()
Sets the current time to the end of this animation. If this animation loop forever, the time is set to the end of the current loop.


rewind

public final void rewind()

update

public boolean update(int elapsedTime)

updateState

protected abstract void updateState(int animTime)
Updates the state based on the animation time, typically from 0 to getDuration(). Note that the duration can be zero.

Parameters:
animTime - The animation time, typically from 0 to getDuration(), although an Easing can cause the value to be outside those bounds.

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.