Class Timeline

java.lang.Object
nl.colorize.util.animation.Timeline
All Implemented Interfaces:
Animatable

public class Timeline extends Object implements Animatable
Animates the value of a property over time by interpolating between key frames. The duration of the animation is equal to the position of the last key fram. Timelines can end once its duration has been reached, or loop to restart playback from the beginning.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a timeline that uses linear interpolation and will not loop.
    Timeline(Interpolation interpolationMethod)
    Creates a timeline that uses the specified interpolation method and will not loop.
    Timeline(Interpolation interpolationMethod, boolean loop)
    Creates a timeline that will interpolate between key frames using the specified interpolation method.
  • Method Summary

    Modifier and Type
    Method
    Description
    addKeyFrame(float position, float value)
    Adds a key frame with the specified position (in seconds) and value.
    Adds a key frame to this timeline.
    void
    end()
    Moves the playhead to the end of the timeline.
    float
    Returns the position of the playhead as a number between 0 and 1, where 0 is the beginning of the timeline and 1 is the timeline's duration.
    float
    Returns this timeline's duration, which is based on the position of the last key frame.
    float
    Returns the current position of the playhead, in seconds.
    float
    Returns the value of the property that is animated by this timeline, based on the current position of the playhead.
    boolean
    Returns true if the playhead is positioned at the start of the timeline.
    boolean
    Returns true if the playhead has reached the end of the timeline.
    boolean
     
    void
    movePlayhead(float deltaTime)
    Moves the playhead by the specified amount, in seconds.
    void
    onFrame(float deltaTime)
    Moves the playhead by the specified amount, in seconds.
    void
     
    void
    Moves the playhead back to the start of the timeline.
    Returns a new timeline that contains the same key frames as this timeline, but in the reverse order.
    void
    setPlayhead(float position)
    Moves the position of the playhead to the specified value, in seconds.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Timeline

      public Timeline(Interpolation interpolationMethod, boolean loop)
      Creates a timeline that will interpolate between key frames using the specified interpolation method.
    • Timeline

      public Timeline(Interpolation interpolationMethod)
      Creates a timeline that uses the specified interpolation method and will not loop.
    • Timeline

      public Timeline()
      Creates a timeline that uses linear interpolation and will not loop.
  • Method Details

    • setPlayhead

      public void setPlayhead(float position)
      Moves the position of the playhead to the specified value, in seconds. The playhead is restricted to the range between zero and the timeline's duration as returned by getDuration().
    • movePlayhead

      public void movePlayhead(float deltaTime)
      Moves the playhead by the specified amount, in seconds. Passing a negative value will move the playhead backwards. The playhead is restricted to the range between zero and the timeline's duration as returned by getDuration().
    • onFrame

      public void onFrame(float deltaTime)
      Moves the playhead by the specified amount, in seconds. Passing a negative value will move the playhead backwards. The playhead is restricted to the range between zero and the timeline's duration as returned by getDuration().
      Specified by:
      onFrame in interface Animatable
      Parameters:
      deltaTime - Time since the last frame update, in seconds.
    • reset

      public void reset()
      Moves the playhead back to the start of the timeline.
    • end

      public void end()
      Moves the playhead to the end of the timeline.
    • getPlayhead

      public float getPlayhead()
      Returns the current position of the playhead, in seconds. The value of the playhead will exist somewhere in the range between zero and the value of getDuration().
    • getDuration

      public float getDuration()
      Returns this timeline's duration, which is based on the position of the last key frame. If the timeline does not contain any key frames, this method will return zero.
    • getDelta

      public float getDelta()
      Returns the position of the playhead as a number between 0 and 1, where 0 is the beginning of the timeline and 1 is the timeline's duration.
    • isAtStart

      public boolean isAtStart()
      Returns true if the playhead is positioned at the start of the timeline.
    • isCompleted

      public boolean isCompleted()
      Returns true if the playhead has reached the end of the timeline.
    • isLoop

      public boolean isLoop()
    • addKeyFrame

      public Timeline addKeyFrame(KeyFrame keyFrame)
      Adds a key frame to this timeline. If the key frame's position is located before the last key frame in this timeline, the new key frame will not be inserted at the end but instead at its appropriate location.
      Returns:
      This timeline, for method chaining.
      Throws:
      IllegalStateException - if this timeline already has a key frame at the same position.
    • addKeyFrame

      public Timeline addKeyFrame(float position, float value)
      Adds a key frame with the specified position (in seconds) and value. If the key frame's position is located before the last key frame in this timeline, the new key frame will not be inserted at the end but instead at its appropriate location.
      Returns:
      This timeline, for method chaining.
      Throws:
      IllegalStateException - if this timeline already has a key frame at the same position.
    • removeKeyFrame

      public void removeKeyFrame(KeyFrame keyFrame)
    • getValue

      public float getValue()
      Returns the value of the property that is animated by this timeline, based on the current position of the playhead. If the playhead is positioned in between key frames, interpolation will be used to determine the current value.
    • reverse

      public Timeline reverse()
      Returns a new timeline that contains the same key frames as this timeline, but in the reverse order. This means the first key frame in the result will have the value of the last key frame in this timeline, and vice versa.
    • toString

      public String toString()
      Overrides:
      toString in class Object