java.lang.Object
de.gurkenlabs.litiengine.graphics.animation.Animation
All Implemented Interfaces:
ILaunchable, IUpdateable

public class Animation
extends java.lang.Object
implements IUpdateable, ILaunchable
The Animation class keeps track of the current keyframe which is used to animate a visual element. It iterates over all defined keyframes with respect to their duration and provides information for the related AnimationController which keyframe should currently be rendered.
See Also:
IAnimationController.getCurrent()
  • Field Summary

    Fields 
    Modifier and TypeFieldDescription
    static intDEFAULT_FRAME_DURATION
    The default frame duration in milliseconds.
  • Constructor Summary

    Constructors 
    ConstructorDescription
    Animation​(Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
    Initializes a new instance of the Animation class.
    Animation​(Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
    Initializes a new instance of the Animation class.
    Animation​(java.lang.String spriteSheetName, boolean loop, boolean randomizeStart, int... keyFrameDurations)
    Initializes a new instance of the Animation class.
    Animation​(java.lang.String name, Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
    Initializes a new instance of the Animation class.
    Animation​(java.lang.String name, Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
    Initializes a new instance of the Animation class.
  • Method Summary

    Modifier and TypeMethodDescription
    int[]getKeyFrameDurations()
    Gets an array of this animation's keyframe durations by streaming the keyframe list and mapping the durations to an int array.
    java.lang.StringgetName()
    Gets the name of this animation.
    SpritesheetgetSpritesheet() 
    intgetTotalDuration()
    Gets to aggregated duration of all KeyFrames in this animation.
    booleanisLooping()
    Gets a value indicating whether this animation intended to loop.
    booleanisPaused()
    Gets a value indicating whether this animation is currently paused.
    booleanisPlaying()
    Gets a value indicating whether this animation is currently playing.
    voidonKeyFrameChanged​(KeyFrameListener listener) 
    voidpause()
    Pauses the playback of this animation.
    voidremoveKeyFrameListener​(KeyFrameListener listener) 
    voidrestart()
    Restarts this animation at its first frame.
    voidsetDurationForAllKeyFrames​(int frameDuration)
    Sets the frame duration for all keyframes in this animation to the specified value.
    voidsetKeyFrameDurations​(int... keyFrameDurations)
    Sets the specified durations for the keyframes at the index of the defined arguments.
    voidsetLooping​(boolean loop)
    Sets the looping behavior for this animation.
    voidstart()
    Starts the operation of this instance.
    voidterminate()
    Terminates the operation of this instance.
    voidunpause()
    Un-pauses the playback of this animation.
    voidupdate()
    This method is called by the game loop on all objects that are attached to the loop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Animation

      public Animation​(java.lang.String spriteSheetName, boolean loop, boolean randomizeStart, int... keyFrameDurations)
      Initializes a new instance of the Animation class.
      Parameters:
      spriteSheetName - The name of the spritesheet used by this animation.
      loop - A flag indicating whether the animation should be looped or played only once.
      randomizeStart - A flag indicating whether this animation should choose a random keyframe to start.
      keyFrameDurations - The duration of each keyframe.
    • Animation

      public Animation​(Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
      Initializes a new instance of the Animation class.
      Parameters:
      spritesheet - The spritesheet used by this animation.
      loop - A flag indicating whether the animation should be looped or played only once.
      randomizeStart - A flag indicating whether this animation should choose a random keyframe to start.
      keyFrameDurations - The duration of each keyframe.
    • Animation

      public Animation​(Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
      Initializes a new instance of the Animation class.
      Parameters:
      spritesheet - The spritesheet used by this animation.
      loop - A flag indicating whether the animation should be looped or played only once.
      keyFrameDurations - The duration of each keyframe.
    • Animation

      public Animation​(java.lang.String name, Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
      Initializes a new instance of the Animation class.
      Parameters:
      name - The name of this animation.
      spritesheet - The spritesheet used by this animation.
      loop - A flag indicating whether the animation should be looped or played only once.
      randomizeStart - A flag indicating whether this animation should choose a random keyframe to start.
      keyFrameDurations - The duration of each keyframe.
    • Animation

      public Animation​(java.lang.String name, Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
      Initializes a new instance of the Animation class.
      Parameters:
      name - The name of this animation.
      spritesheet - The spritesheet used by this animation.
      loop - A flag indicating whether the animation should be looped or played only once.
      keyFrameDurations - The duration of each keyframe.
  • Method Details

    • getTotalDuration

      public int getTotalDuration()
      Gets to aggregated duration of all KeyFrames in this animation.
      Returns:
      The total duration of a single playback.
    • getName

      public java.lang.String getName()
      Gets the name of this animation.
      Returns:
      The name of this animation.
    • getSpritesheet

      public Spritesheet getSpritesheet()
    • isLooping

      public boolean isLooping()
      Gets a value indicating whether this animation intended to loop.
      Returns:
      True if this animation will loop; otherwise false.
    • isPaused

      public boolean isPaused()
      Gets a value indicating whether this animation is currently paused.
      Returns:
      True if this animation is currently pause; otherwise false.
    • isPlaying

      public boolean isPlaying()
      Gets a value indicating whether this animation is currently playing.
      Returns:
      True if this animation is currently playing; otherwise false.
    • pause

      public void pause()
      Pauses the playback of this animation.
      See Also:
      isPaused(), unpause()
    • unpause

      public void unpause()
      Un-pauses the playback of this animation.
      See Also:
      isPaused(), pause()
    • setDurationForAllKeyFrames

      public void setDurationForAllKeyFrames​(int frameDuration)
      Sets the frame duration for all keyframes in this animation to the specified value.
      Parameters:
      frameDuration - The frameduration for all keyframes.
    • setKeyFrameDurations

      public void setKeyFrameDurations​(int... keyFrameDurations)
      Sets the specified durations for the keyframes at the index of the defined arguments.

      e.g.: If this animation defines 5 keyframes, the caller of this method can provide 5 individual durations for each keyframe.

      Parameters:
      keyFrameDurations - The durations to be set on the keyframes of this animation.
    • getKeyFrameDurations

      public int[] getKeyFrameDurations()
      Gets an array of this animation's keyframe durations by streaming the keyframe list and mapping the durations to an int array.
      Returns:
      An array of this animation's keyframe durations.
    • setLooping

      public void setLooping​(boolean loop)
      Sets the looping behavior for this animation.
      Parameters:
      loop - if true, restart the animation infinitely after its last frame.
    • onKeyFrameChanged

      public void onKeyFrameChanged​(KeyFrameListener listener)
    • removeKeyFrameListener

      public void removeKeyFrameListener​(KeyFrameListener listener)
    • start

      public void start()
      Description copied from interface: ILaunchable
      Starts the operation of this instance.
      Specified by:
      start in interface ILaunchable
    • restart

      public void restart()
      Restarts this animation at its first frame.
    • terminate

      public void terminate()
      Description copied from interface: ILaunchable
      Terminates the operation of this instance.
      Specified by:
      terminate in interface ILaunchable
    • update

      public void update()
      Description copied from interface: IUpdateable
      This method is called by the game loop on all objects that are attached to the loop. It's called on every tick of the loop and the frequency can be configured using the ClientConfiguration.
      Specified by:
      update in interface IUpdateable
      See Also:
      ClientConfiguration.setMaxFps(int)