[libgdx] Improved AnimationState behavior when paused.

Ie, when time scale is 0 or `update(0)` is used.

* Better check for whether the from entry has been applied at least once.
* Discard the from entry if both the from and to entries haven't advanced. Ie, the mix hasn't started for the from entry.
This commit is contained in:
Nathan Sweet 2024-12-06 12:43:55 -10:00
parent a4b5605921
commit 8d058fb4f4

View File

@ -180,10 +180,11 @@ public class AnimationState {
from.animationLast = from.nextAnimationLast; from.animationLast = from.nextAnimationLast;
from.trackLast = from.nextTrackLast; from.trackLast = from.nextTrackLast;
// Require mixTime > 0 to ensure the mixing from entry was applied at least once. if (to.nextTrackLast != -1) { // The from entry was applied at least once.
if (to.mixTime > 0 && to.mixTime >= to.mixDuration) { boolean discard = to.mixTime == 0 && from.mixTime == 0; // Discard the from entry when neither have advanced yet.
// Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame). if (to.mixTime >= to.mixDuration || discard) {
if (from.totalAlpha == 0 || to.mixDuration == 0) { // Require totalAlpha == 0 to ensure mixing is complete or the transition is a single frame or discarded.
if (from.totalAlpha == 0 || to.mixDuration == 0 || discard) {
to.mixingFrom = from.mixingFrom; to.mixingFrom = from.mixingFrom;
if (from.mixingFrom != null) from.mixingFrom.mixingTo = to; if (from.mixingFrom != null) from.mixingFrom.mixingTo = to;
to.interruptAlpha = from.interruptAlpha; to.interruptAlpha = from.interruptAlpha;
@ -191,6 +192,7 @@ public class AnimationState {
} }
return finished; return finished;
} }
}
from.trackTime += delta * from.timeScale; from.trackTime += delta * from.timeScale;
to.mixTime += delta; to.mixTime += delta;