Skip to content

Commit 119a70e

Browse files
committed
Fixed sprite animation groups not advancing to their first frame immediately
1 parent 94f977d commit 119a70e

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ MLEM uses [semantic versioning](https://semver.org/). Potentially breaking chang
33

44
## 8.1.0 (In Development)
55

6+
### MLEM
7+
Fixes
8+
- Fixed sprite animation groups not advancing to their first frame immediately
9+
610
### MLEM.Ui
711
Additions
812
- Added UiSystem.OnElementAreaDirty and Element.OnAreaDirty events

MLEM/Animations/SpriteAnimationGroup.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public class SpriteAnimationGroup : GenericDataHolder {
1616
/// </summary>
1717
public SpriteAnimation CurrentAnimation {
1818
get {
19-
this.SortAnimationsIfDirty(true);
19+
if (this.SortAnimationsIfDirty() || this.currentAnimation == null)
20+
this.FindAnimationToPlay();
2021
return this.currentAnimation?.Animation;
2122
}
2223
}
@@ -99,7 +100,7 @@ public SpriteAnimation ByName(string name) {
99100
}
100101

101102
private void FindAnimationToPlay() {
102-
this.SortAnimationsIfDirty(false);
103+
this.SortAnimationsIfDirty();
103104

104105
ConditionedAnimation animToPlay = null;
105106
if (this.currentAnimation != null && this.currentAnimation.ShouldPlay())
@@ -122,13 +123,12 @@ private void FindAnimationToPlay() {
122123
}
123124
}
124125

125-
private void SortAnimationsIfDirty(bool findAnimationToPlay) {
126-
if (this.animationsDirty) {
127-
this.animationsDirty = false;
128-
this.animations.Sort((a1, a2) => a2.Priority.CompareTo(a1.Priority));
129-
if (findAnimationToPlay)
130-
this.FindAnimationToPlay();
131-
}
126+
private bool SortAnimationsIfDirty() {
127+
if (!this.animationsDirty)
128+
return false;
129+
this.animationsDirty = false;
130+
this.animations.Sort((a1, a2) => a2.Priority.CompareTo(a1.Priority));
131+
return true;
132132
}
133133

134134
/// <summary>

0 commit comments

Comments
 (0)