1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-29 15:58:33 +01:00

allow sprite animations to be updated by a time span

This commit is contained in:
Ellpeck 2020-08-13 19:46:49 +02:00
parent 86d1ac18fc
commit a5c1b6c2b4
2 changed files with 15 additions and 6 deletions

View file

@ -112,13 +112,17 @@ namespace MLEM.Animations {
/// </summary>
/// <param name="time">The game's time</param>
public void Update(GameTime time) {
this.SetTime(this.TimeIntoAnimation + time.ElapsedGameTime.TotalSeconds * this.SpeedMultiplier);
this.Update(time.ElapsedGameTime);
}
internal void SetTime(double totalTime) {
/// <summary>
/// Updates this animation, causing <see cref="TimeIntoAnimation"/> to be increased and the <see cref="CurrentFrame"/> to be updated.
/// </summary>
/// <param name="elapsed">The amount of time that has passed</param>
public void Update(TimeSpan elapsed) {
if (this.IsFinished || this.IsPaused)
return;
this.TimeIntoAnimation = totalTime;
this.TimeIntoAnimation += elapsed.TotalSeconds * this.SpeedMultiplier;
if (this.TimeIntoAnimation >= this.TotalTime) {
if (!this.IsLooping) {
this.IsFinished = true;

View file

@ -62,11 +62,16 @@ namespace MLEM.Animations {
return this;
}
/// <inheritdoc cref="SpriteAnimation.Update"/>
/// <inheritdoc cref="SpriteAnimation.Update(GameTime)"/>
public void Update(GameTime time) {
this.Update(time.ElapsedGameTime);
}
/// <inheritdoc cref="SpriteAnimation.Update(TimeSpan)"/>
public void Update(TimeSpan elapsed) {
this.FindAnimationToPlay();
if (this.CurrAnimation != null)
this.CurrAnimation.Animation.Update(time);
this.CurrAnimation.Animation.Update(elapsed);
}
/// <summary>