Class Animation<T>


  • public class Animation<T>
    extends java.lang.Object

    An Animation stores a list of objects representing an animated sequence, e.g. for running or jumping. Each object in the Animation is called a key frame, and multiple key frames make up the animation.

    The animation's type is the class representing a frame of animation. For example, a typical 2D animation could be made up of TextureRegions and would be specified as:

    Animation<TextureRegion> myAnimation = new Animation<TextureRegion>(...);

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Animation.PlayMode
      Defines possible playback modes for an Animation.
    • Constructor Summary

      Constructors 
      Constructor Description
      Animation​(float frameDuration, Array<? extends T> keyFrames)
      Constructor, storing the frame duration and key frames.
      Animation​(float frameDuration, Array<? extends T> keyFrames, Animation.PlayMode playMode)
      Constructor, storing the frame duration and key frames.
      Animation​(float frameDuration, T... keyFrames)
      Constructor, storing the frame duration and key frames.
    • Constructor Detail

      • Animation

        public Animation​(float frameDuration,
                         Array<? extends T> keyFrames)
        Constructor, storing the frame duration and key frames.
        Parameters:
        frameDuration - the time between frames in seconds.
        keyFrames - the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].
      • Animation

        public Animation​(float frameDuration,
                         Array<? extends T> keyFrames,
                         Animation.PlayMode playMode)
        Constructor, storing the frame duration and key frames.
        Parameters:
        frameDuration - the time between frames in seconds.
        keyFrames - the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].
      • Animation

        public Animation​(float frameDuration,
                         T... keyFrames)
        Constructor, storing the frame duration and key frames.
        Parameters:
        frameDuration - the time between frames in seconds.
        keyFrames - the objects representing the frames.
    • Method Detail

      • getKeyFrame

        public T getKeyFrame​(float stateTime,
                             boolean looping)
        Returns a frame based on the so called state time. This is the amount of seconds an object has spent in the state this Animation instance represents, e.g. running, jumping and so on. The mode specifies whether the animation is looping or not.
        Parameters:
        stateTime - the time spent in the state represented by this animation.
        looping - whether the animation is looping or not.
        Returns:
        the frame of animation for the given state time.
      • getKeyFrame

        public T getKeyFrame​(float stateTime)
        Returns a frame based on the so called state time. This is the amount of seconds an object has spent in the state this Animation instance represents, e.g. running, jumping and so on using the mode specified by setPlayMode(PlayMode) method.
        Parameters:
        stateTime -
        Returns:
        the frame of animation for the given state time.
      • getKeyFrameIndex

        public int getKeyFrameIndex​(float stateTime)
        Returns the current frame number.
        Parameters:
        stateTime -
        Returns:
        current frame number
      • getKeyFrames

        public T[] getKeyFrames()
        Returns the keyframes[] array where all the frames of the animation are stored.
        Returns:
        The keyframes[] field. This array is an Object[] if the animation was instantiated with an Array that was not type-aware.
      • setKeyFrames

        protected void setKeyFrames​(T... keyFrames)
      • isAnimationFinished

        public boolean isAnimationFinished​(float stateTime)
        Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.
        Parameters:
        stateTime -
        Returns:
        whether the animation is finished.
      • setFrameDuration

        public void setFrameDuration​(float frameDuration)
        Sets duration a frame will be displayed.
        Parameters:
        frameDuration - in seconds
      • getFrameDuration

        public float getFrameDuration()
        Returns:
        the duration of a frame in seconds
      • getAnimationDuration

        public float getAnimationDuration()
        Returns:
        the duration of the entire animation, number of frames times frame duration, in seconds