From 1ec8416ab7c096b82e640eee46f7aea4a22f6e2e Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 9 Jan 2020 21:38:04 +0100 Subject: [PATCH] allowed to set a speed multiplier for animations --- MLEM/Animations/SpriteAnimation.cs | 5 +++-- MLEM/Animations/SpriteAnimationGroup.cs | 6 ++++++ MLEM/Formatting/TextFormatting.cs | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MLEM/Animations/SpriteAnimation.cs b/MLEM/Animations/SpriteAnimation.cs index 43de748..615fadc 100644 --- a/MLEM/Animations/SpriteAnimation.cs +++ b/MLEM/Animations/SpriteAnimation.cs @@ -28,6 +28,7 @@ namespace MLEM.Animations { public double TimeIntoAnimation { get; private set; } public bool IsFinished { get; private set; } public string Name; + public float SpeedMultiplier = 1; public bool IsLooping = true; public Completed OnCompleted; @@ -48,10 +49,10 @@ namespace MLEM.Animations { } public void Update(GameTime time) { - this.SetTime(this.TimeIntoAnimation + time.ElapsedGameTime.TotalSeconds); + this.SetTime(this.TimeIntoAnimation + time.ElapsedGameTime.TotalSeconds * this.SpeedMultiplier); } - public void SetTime(double totalTime) { + internal void SetTime(double totalTime) { if (this.IsFinished || this.IsPaused) return; this.TimeIntoAnimation = totalTime; diff --git a/MLEM/Animations/SpriteAnimationGroup.cs b/MLEM/Animations/SpriteAnimationGroup.cs index 4a8651b..082345d 100644 --- a/MLEM/Animations/SpriteAnimationGroup.cs +++ b/MLEM/Animations/SpriteAnimationGroup.cs @@ -24,6 +24,12 @@ namespace MLEM.Animations { public TextureRegion CurrentRegion => this.CurrentAnimation?.CurrentRegion; public AnimationChanged OnAnimationChanged; private bool isDirty; + public float SpeedMultiplier { + set { + foreach (var anim in this.animations) + anim.Animation.SpeedMultiplier = value; + } + } public SpriteAnimationGroup Add(SpriteAnimation anim, Func condition, int priority = 0) { this.animations.Add(new ConditionedAnimation(anim, condition, priority)); diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index c95b869..158ebce 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -108,7 +108,7 @@ namespace MLEM.Formatting { currStyle = code.Style; break; case FormattingCode.Type.Icon: - code.Icon.SetTime(timeIntoAnimation.TotalSeconds % code.Icon.TotalTime); + code.Icon.SetTime(timeIntoAnimation.TotalSeconds * code.Icon.SpeedMultiplier % code.Icon.TotalTime); batch.Draw(code.Icon.CurrentRegion, new RectangleF(pos + innerOffset, new Vector2(regularFont.LineHeight * scale)), color, 0, Vector2.Zero, SpriteEffects.None, depth); break; case FormattingCode.Type.Animation: