[libgdx] Fixed delay being negative, causing the track time to jump.

This commit is contained in:
Nathan Sweet 2025-04-09 14:17:46 -04:00 committed by Mario Zechner
parent c9aca368d6
commit 262a0d270f

View File

@ -636,10 +636,11 @@ public class AnimationState {
if (last == null) { if (last == null) {
setCurrent(trackIndex, entry, true); setCurrent(trackIndex, entry, true);
queue.drain(); queue.drain();
if (delay < 0) delay = 0;
} else { } else {
last.next = entry; last.next = entry;
entry.previous = last; entry.previous = last;
if (delay <= 0) delay += last.getTrackComplete() - entry.mixDuration; if (delay <= 0) delay = Math.max(delay + last.getTrackComplete() - entry.mixDuration, 0);
} }
entry.delay = delay; entry.delay = delay;
@ -681,7 +682,7 @@ public class AnimationState {
* after the {@link AnimationStateListener#dispose(TrackEntry)} event occurs. */ * after the {@link AnimationStateListener#dispose(TrackEntry)} event occurs. */
public TrackEntry addEmptyAnimation (int trackIndex, float mixDuration, float delay) { public TrackEntry addEmptyAnimation (int trackIndex, float mixDuration, float delay) {
TrackEntry entry = addAnimation(trackIndex, emptyAnimation, false, delay); TrackEntry entry = addAnimation(trackIndex, emptyAnimation, false, delay);
if (delay <= 0) entry.delay += entry.mixDuration - mixDuration; if (delay <= 0) entry.delay = Math.max(entry.delay + entry.mixDuration - mixDuration, 0);
entry.mixDuration = mixDuration; entry.mixDuration = mixDuration;
entry.trackEnd = mixDuration; entry.trackEnd = mixDuration;
return entry; return entry;
@ -940,21 +941,23 @@ public class AnimationState {
this.loop = loop; this.loop = loop;
} }
/** Seconds to postpone playing the animation. When this track entry is the current track entry, <code>delay</code> /** Seconds to postpone playing the animation. Must be >= 0. When this track entry is the current track entry,
* postpones incrementing the {@link #getTrackTime()}. When this track entry is queued, <code>delay</code> is the time from * <code>delay</code> postpones incrementing the {@link #getTrackTime()}. When this track entry is queued,
* the start of the previous animation to when this track entry will become the current track entry (ie when the previous * <code>delay</code> is the time from the start of the previous animation to when this track entry will become the current
* track entry {@link TrackEntry#getTrackTime()} >= this track entry's <code>delay</code>). * track entry (ie when the previous track entry {@link TrackEntry#getTrackTime()} >= this track entry's
* <code>delay</code>).
* <p> * <p>
* {@link #getTimeScale()} affects the delay. * {@link #getTimeScale()} affects the delay.
* <p> * <p>
* When using {@link AnimationState#addAnimation(int, Animation, boolean, float)} with a <code>delay</code> <= 0, the delay * When passing <code>delay</code> <= 0 to {@link AnimationState#addAnimation(int, Animation, boolean, float)} this
* is set using the mix duration from the {@link AnimationStateData}. If {@link #mixDuration} is set afterward, the delay * <code>delay</code> is set using a mix duration from {@link AnimationStateData}. To change the {@link #getMixDuration()}
* may need to be adjusted. */ * afterward, use {@link #setMixDuration(float, float)} so this <code>delay</code> is adjusted. */
public float getDelay () { public float getDelay () {
return delay; return delay;
} }
public void setDelay (float delay) { public void setDelay (float delay) {
if (delay < 0) throw new IllegalArgumentException("delay must be >= 0.");
this.delay = delay; this.delay = delay;
} }
@ -1211,7 +1214,12 @@ public class AnimationState {
* entry is looping, its next loop completion is used instead of its duration. */ * entry is looping, its next loop completion is used instead of its duration. */
public void setMixDuration (float mixDuration, float delay) { public void setMixDuration (float mixDuration, float delay) {
this.mixDuration = mixDuration; this.mixDuration = mixDuration;
if (previous != null && delay <= 0) delay += previous.getTrackComplete() - mixDuration; if (delay <= 0) {
if (previous != null)
delay = Math.max(delay + previous.getTrackComplete() - mixDuration, 0);
else
delay = 0;
}
this.delay = delay; this.delay = delay;
} }
@ -1275,7 +1283,7 @@ public class AnimationState {
} }
/** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the /** Resets the rotation directions for mixing this entry's rotate timelines. This can be useful to avoid bones rotating the
* long way around when using {@link #alpha} and starting animations on other tracks. * long way around when using {@link #getAlpha()} and starting animations on other tracks.
* <p> * <p>
* Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions: * Mixing with {@link MixBlend#replace} involves finding a rotation between two others, which has two possible solutions:
* the short way or the long way around. The two rotations likely change over time, so which direction is the short or long * the short way or the long way around. The two rotations likely change over time, so which direction is the short or long