Class Animator
A Component that renders animated sprites by cycling through frames form a SpriteSheet.
public class Animator : SpriteRenderer, IDisposable
- Inheritance
-
Animator
- Implements
- Inherited Members
Constructors
Animator(SpriteSheet)
Initializes a new instance of the Animator class with a default animation using all frames in the sheet.
public Animator(SpriteSheet spriteSheet)
Parameters
spriteSheetSpriteSheetThe source sprite sheet containing the frames.
Animator(SpriteSheet, Animation[])
Initializes a new instance of the Animator class with a given set of named animations.
public Animator(SpriteSheet spriteSheet, Animation[] animations)
Parameters
spriteSheetSpriteSheetThe source sprite sheet containing the frames.
animationsAnimation[]The array of animations to register.
Exceptions
- Exception
Thrown if the animations array is empty.
Fields
OnChanged
Invoked when the current animation is switched to a new one. Provides the name of the new animation.
public Action<string> OnChanged
Field Value
OnFinished
Invoked when a non-looping animation reaches its final frame. Provides the name of the finished animation.
public Action<string> OnFinished
Field Value
OnLooped
Invoked when the current animation completes a cycle and loops back to the start.
public Action OnLooped
Field Value
OnPlayed
Invoked when playback starts or resumes.
public Action OnPlayed
Field Value
OnStopped
Invoked when playback is stopped manually or when a non looping animation finishes.
public Action OnStopped
Field Value
Properties
FrameDuration
Gets or sets the default duration, in seconds, for each frame. Used only for the default animation created in the constructor.
public float FrameDuration { get; init; }
Property Value
Loop
Gets or sets a value indicating whether the default animation should loop. Used only for the default animation created in the constructor.
public bool Loop { get; init; }
Property Value
Methods
Pause()
Pauses playback.
public void Pause()
Play()
Starts or resumes playback of the current animation.
public void Play()
Play(string)
Switches to the given animation and starts playback from the beginning.
public void Play(string animationName)
Parameters
animationNamestringThe name of the animation to play.
Remarks
If the specified animation is already playing, this method does nothing, unless Stop() was called previously.
Exceptions
- Exception
Thrown if the animation name is not found.
Resume()
Resumes playback from the current frame.
public void Resume()
Stop()
Stops playback. The sprite remains on the current frame.
public void Stop()
Update()
Called once per frame to update game logic.
protected override void Update()