1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 17:29:23 +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 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;

View file

@ -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<bool> condition, int priority = 0) {
this.animations.Add(new ConditionedAnimation(anim, condition, priority));

View file

@ -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: