1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

allowed to set a speed multiplier for animations

This commit is contained in:
Ellpeck 2020-01-09 21:38:04 +01:00
parent cba644e300
commit 1ec8416ab7
3 changed files with 10 additions and 3 deletions

View file

@ -28,6 +28,7 @@ namespace MLEM.Animations {
public double TimeIntoAnimation { get; private set; } public double TimeIntoAnimation { get; private set; }
public bool IsFinished { get; private set; } public bool IsFinished { get; private set; }
public string Name; public string Name;
public float SpeedMultiplier = 1;
public bool IsLooping = true; public bool IsLooping = true;
public Completed OnCompleted; public Completed OnCompleted;
@ -48,10 +49,10 @@ namespace MLEM.Animations {
} }
public void Update(GameTime time) { 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) if (this.IsFinished || this.IsPaused)
return; return;
this.TimeIntoAnimation = totalTime; this.TimeIntoAnimation = totalTime;

View file

@ -24,6 +24,12 @@ namespace MLEM.Animations {
public TextureRegion CurrentRegion => this.CurrentAnimation?.CurrentRegion; public TextureRegion CurrentRegion => this.CurrentAnimation?.CurrentRegion;
public AnimationChanged OnAnimationChanged; public AnimationChanged OnAnimationChanged;
private bool isDirty; private bool isDirty;
public float SpeedMultiplier {
set {
foreach (var anim in this.animations)
anim.Animation.SpeedMultiplier = value;
}
}
public SpriteAnimationGroup Add(SpriteAnimation anim, Func<bool> condition, int priority = 0) { public SpriteAnimationGroup Add(SpriteAnimation anim, Func<bool> condition, int priority = 0) {
this.animations.Add(new ConditionedAnimation(anim, condition, priority)); this.animations.Add(new ConditionedAnimation(anim, condition, priority));

View file

@ -108,7 +108,7 @@ namespace MLEM.Formatting {
currStyle = code.Style; currStyle = code.Style;
break; break;
case FormattingCode.Type.Icon: 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); batch.Draw(code.Icon.CurrentRegion, new RectangleF(pos + innerOffset, new Vector2(regularFont.LineHeight * scale)), color, 0, Vector2.Zero, SpriteEffects.None, depth);
break; break;
case FormattingCode.Type.Animation: case FormattingCode.Type.Animation: