Package nl.colorize.util.animation
Class Timeline
java.lang.Object
nl.colorize.util.animation.Timeline
- All Implemented Interfaces:
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
ConstructorDescriptionTimeline()
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 TypeMethodDescriptionaddKeyFrame
(float position, float value) Adds a key frame with the specified position (in seconds) and value.addKeyFrame
(KeyFrame keyFrame) Adds a key frame to this timeline.void
end()
Moves the playhead to the end of the timeline.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.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
getValue()
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
isLoop()
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
removeKeyFrame
(KeyFrame keyFrame) void
reset()
Moves the playhead back to the start of the timeline.reverse()
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.toString()
-
Constructor Details
-
Timeline
Creates a timeline that will interpolate between key frames using the specified interpolation method. -
Timeline
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 bygetDuration()
. -
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 bygetDuration()
. -
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 bygetDuration()
.- Specified by:
onFrame
in interfaceAnimatable
- 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 ofgetDuration()
. -
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
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
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
-
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
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
-