Skip to content

Class Animator<T, V>

Definition

Namespace: StardewUI.Animation
Assembly: StardewUI.dll

Animates a single property of a single class.

public class Animator<T, V>

Type Parameters

T
The target class that will receive the animation.

V
The type of value belonging to T that should be animated.

Inheritance
Object ⇦ Animator<T, V>

Members

Constructors

Name Description
Animator<T, V>(T, Func<T, V>, Lerp<V>, Action<T, V>) Initializes a new Animator<T, V>.

Properties

Name Description
AutoReverse Whether to automatically start playing in reverse after reaching the end.
CurrentAnimation The current animation, if any, started by Start(Animation<V>) or any Start overloads.
IsReversing Gets whether or not the animator is currently animating in Reverse().
Loop Whether or not the animation should automatically loop back to the beginning when finished.
Paused Whether or not to pause animation. If true, the animator will hold at the current position and not progress until set to false again. Does not affect the CurrentAnimation.

Methods

Name Description
Forward() Causes the animator to animate in the forward direction toward animation's EndValue.
Reset() Jumps to the first frame of the current animation, or the last frame if IsReversing is true.
Reverse() Reverses the current animation, so that it gradually returns to the animation's StartValue.
Start(Animation<V>) Starts a new animation.
Start(V, V, TimeSpan?) Starts a new animation using the specified start/end values and duration.
Start(V, TimeSpan) Starts a new animation that begins at the current value and ends at the specified value after the specified duration.
Stop() Completely stops animating, removing the CurrentAnimation and resetting animation state such as Reverse() and Paused.
Tick(TimeSpan) Continues animating in the current direction.

Details

Constructors

Animator<T, V>(T, Func<T, V>, Lerp<V>, Action<T, V>)

Initializes a new Animator<T, V>.

public Animator<T, V>(T target, Func<T, V> getValue, StardewUI.Animation.Lerp<V> lerpValue, Action<T, V> setValue);
Parameters

target   T
The object whose property will be animated.

getValue   Func<T, V>
Function to get the current value. Used for animations that don't explicit specify a start value, e.g. when using the Start(Animation<V>) overload.

lerpValue   Lerp<V>
Function to linearly interpolate between the start and end values.

setValue   Action<T, V>
Delegate to set the value on the target.


Properties

AutoReverse

Whether to automatically start playing in reverse after reaching the end.

public bool AutoReverse { get; set; }
Property Value

Boolean


CurrentAnimation

The current animation, if any, started by Start(Animation<V>) or any Start overloads.

public StardewUI.Animation.Animation<V> CurrentAnimation { get; private set; }
Property Value

Animation<V>


IsReversing

Gets whether or not the animator is currently animating in Reverse().

public bool IsReversing { get; private set; }
Property Value

Boolean


Loop

Whether or not the animation should automatically loop back to the beginning when finished.

public bool Loop { get; set; }
Property Value

Boolean


Paused

Whether or not to pause animation. If true, the animator will hold at the current position and not progress until set to false again. Does not affect the CurrentAnimation.

public bool Paused { get; set; }
Property Value

Boolean


Methods

Forward()

Causes the animator to animate in the forward direction toward animation's EndValue.

public void Forward();
Remarks

Does not restart the animation; if the animator is not reversed, then calling this has no effect.


Reset()

Jumps to the first frame of the current animation, or the last frame if IsReversing is true.

public void Reset();
Remarks

Has no effect unless CurrentAnimation has been set by a previous call to one of the Start(Animation<V>) overloads.


Reverse()

Reverses the current animation, so that it gradually returns to the animation's StartValue.

public void Reverse();
Remarks

Calling Reverse() is different from starting a new animation with reversed start and end values; specifically, it will follow the timeline/curve backward from the current progress. If only 1/4 second of a 1-second animation elapsed in the forward direction, then the reverse animation will also only take 1/4 second.


Start(Animation<V>)

Starts a new animation.

public void Start(StardewUI.Animation.Animation<V> animation);
Parameters

animation   Animation<V>
The animation settings.


Start(V, V, TimeSpan?)

Starts a new animation using the specified start/end values and duration.

public void Start(V startValue, V endValue, System.TimeSpan? duration);
Parameters

startValue   V
The initial value of the animation property. This will take effect immediately, even if it is far away from the current value; i.e. it may cause "jumps".

endValue   V
The final value to be reached once the duration ends.

duration   Nullable<TimeSpan>
Duration of the animation; defaults to 1 second if not specified.


Start(V, TimeSpan)

Starts a new animation that begins at the current value and ends at the specified value after the specified duration.

public void Start(V endValue, System.TimeSpan duration);
Parameters

endValue   V
The final value to be reached once the duration ends.

duration   TimeSpan
Duration of the animation; defaults to 1 second if not specified.


Stop()

Completely stops animating, removing the CurrentAnimation and resetting animation state such as Reverse() and Paused.

public void Stop();
Remarks

This tries to put the animator in the same state it was in when first created. To preserve the current animation but pause progress and be able to resume later, set Paused instead.

Calling this does not reset the animated object to the animation's starting value. To do this, call Reset() before calling Stop() (not after, as Reset() has no effect once the CurrentAnimation is cleared).


Tick(TimeSpan)

Continues animating in the current direction.

public void Tick(System.TimeSpan elapsed);
Parameters

elapsed   TimeSpan
Time elapsed since last tick.