Class SpriteAnimation
- Namespace
- MLEM.Animations
- Assembly
- MLEM.dll
A sprite animation that allows for any number of frames that each last any number of seconds
public class SpriteAnimation : GenericDataHolder, IGenericDataHolder
- Inheritance
-
SpriteAnimation
- Implements
- Inherited Members
Constructors
SpriteAnimation(params AnimationFrame[])
Creates a new sprite animation that contains the given frames.
public SpriteAnimation(params AnimationFrame[] frames)
Parameters
frames
AnimationFrame[]The frames this animation should have
SpriteAnimation(double, params TextureRegion[])
Creates a new sprite animation that contains the given texture regions as frames.
public SpriteAnimation(double timePerFrame, params TextureRegion[] regions)
Parameters
timePerFrame
doubleThe amount of time that each frame should last for
regions
TextureRegion[]The texture regions that should make up this animation
SpriteAnimation(double, params TextureRegion[][])
Creates a new sprite animation that contains the given texture region arrays as frames, where each frame represents one set of texture regions.
public SpriteAnimation(double timePerFrame, params TextureRegion[][] regions)
Parameters
timePerFrame
doubleThe amount of time that each frame should last for
regions
TextureRegion[][]The texture regions that should make up this animation
SpriteAnimation(double, Texture2D, params Rectangle[])
Creates a new sprite animation based on the given texture regions in rectangle-based format.
public SpriteAnimation(double timePerFrame, Texture2D texture, params Rectangle[] regions)
Parameters
timePerFrame
doubleThe amount of time that each frame should last for
texture
Texture2DThe texture that the regions should come from
regions
Rectangle[]The texture regions that should make up this animation
Fields
IsLooping
Set to false to stop this animation from looping. To check if the animation has finished playing, see IsFinished.
public bool IsLooping
Field Value
IsPaused
Set this to true to pause the playback of the animation. TimeIntoAnimation will not continue and the CurrentFrame will not change.
public bool IsPaused
Field Value
Name
The name of this animation. This is useful if used in combination with SpriteAnimationGroup.
public string Name
Field Value
SpeedMultiplier
The speed multiplier that this animation should run with. Numbers higher than 1 will increase the speed.
public float SpeedMultiplier
Field Value
TotalTime
The total amount of time that this animation has. This is auatomatically calculated based on the frame time of each frame.
public readonly double TotalTime
Field Value
Properties
Count
Returns the amount of AnimationFrame entries that this sprite animation has.
public int Count { get; }
Property Value
CurrentFrame
The frame that the animation is currently on.
public AnimationFrame CurrentFrame { get; }
Property Value
CurrentRegion
The texture region that this animation's CurrentFrame should render. If there are multiple regions, CurrentRegions should be used instead.
public TextureRegion CurrentRegion { get; }
Property Value
CurrentRegions
The texture regions that this animation's CurrentFrame should render. If there is only one region, CurrentRegion can be used for convenience.
public IList<TextureRegion> CurrentRegions { get; }
Property Value
IsFinished
The finished state of this animation. This is only true for longer than a frame if IsLooping is false.
public bool IsFinished { get; }
Property Value
this[int]
Returns the AnimationFrame at the given index. Index ordering is based on the order that animation frames were added in.
public AnimationFrame this[int index] { get; }
Parameters
index
intThe index in the list of animation frames
Property Value
TimeIntoAnimation
The amount of seconds that the animation has been going on for. If TotalTime is reached, this value resets to 0.
public double TimeIntoAnimation { get; }
Property Value
Methods
Restart()
Restarts this animation from the first frame.
public void Restart()
Update(GameTime)
Updates this animation, causing TimeIntoAnimation to be increased and the CurrentFrame to be updated.
public void Update(GameTime time)
Parameters
time
GameTimeThe game's time
Update(TimeSpan)
Updates this animation, causing TimeIntoAnimation to be increased and the CurrentFrame to be updated.
public void Update(TimeSpan elapsed)
Parameters
elapsed
TimeSpanThe amount of time that has passed
Events
OnCompleted
A callback that gets fired when the animation completes.
public event SpriteAnimation.Completed OnCompleted