From a5c1b6c2b4422386d546f9354bd34ed7aab3cc06 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 13 Aug 2020 19:46:49 +0200 Subject: [PATCH] allow sprite animations to be updated by a time span --- MLEM/Animations/SpriteAnimation.cs | 12 ++++++++---- MLEM/Animations/SpriteAnimationGroup.cs | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/MLEM/Animations/SpriteAnimation.cs b/MLEM/Animations/SpriteAnimation.cs index d35b29f..a85af4c 100644 --- a/MLEM/Animations/SpriteAnimation.cs +++ b/MLEM/Animations/SpriteAnimation.cs @@ -112,13 +112,17 @@ namespace MLEM.Animations { /// /// The game's time public void Update(GameTime time) { - this.SetTime(this.TimeIntoAnimation + time.ElapsedGameTime.TotalSeconds * this.SpeedMultiplier); + this.Update(time.ElapsedGameTime); } - - internal void SetTime(double totalTime) { + + /// + /// Updates this animation, causing to be increased and the to be updated. + /// + /// The amount of time that has passed + 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; diff --git a/MLEM/Animations/SpriteAnimationGroup.cs b/MLEM/Animations/SpriteAnimationGroup.cs index c52bba8..e7f8146 100644 --- a/MLEM/Animations/SpriteAnimationGroup.cs +++ b/MLEM/Animations/SpriteAnimationGroup.cs @@ -62,11 +62,16 @@ namespace MLEM.Animations { return this; } - /// + /// public void Update(GameTime time) { + this.Update(time.ElapsedGameTime); + } + + /// + public void Update(TimeSpan elapsed) { this.FindAnimationToPlay(); if (this.CurrAnimation != null) - this.CurrAnimation.Animation.Update(time); + this.CurrAnimation.Animation.Update(elapsed); } ///