Always mix, even when mix duration is 0, to give the old animation a chance to reset its changes.

This commit is contained in:
NathanSweet 2016-08-22 19:39:48 +02:00
parent 42e3b95e33
commit ef2a440655
2 changed files with 39 additions and 21 deletions

View File

@ -511,13 +511,28 @@ public class AnimationStateTest {
expect(1, "event 0", 0, 0), // expect(1, "event 0", 0, 0), //
expect(1, "event 14", 0.5f, 0.5f), // expect(1, "event 14", 0.5f, 0.5f), //
expect(1, "event 30", 1, 1), //
expect(1, "complete", 1, 1), // expect(0, "start", 0.1f, 0.8f), //
expect(1, "end", 1, 1.1f) //
expect(1, "interrupt", 0.8f, 0.8f), //
expect(1, "end", 0.8f, 0.8f), //
expect(0, "event 0", 0.1f, 0.8f), //
expect(0, "event 14", 0.5f, 1.2f), //
expect(0, "event 30", 1, 1.7f), //
expect(0, "complete", 1, 1.7f), //
expect(0, "end", 1, 1.8f) //
); );
state.setAnimation(0, "events1", false); // First should be ignored. state.setAnimation(0, "events1", false); // First should be ignored.
state.setAnimation(0, "events2", false); state.setAnimation(0, "events2", false);
run(0.1f, 1000, null); run(0.1f, 1000, new TestListener() {
public void frame (float time) {
if (MathUtils.isEqual(time, 0.8f)) {
state.setAnimation(0, "events2", false); // First should be ignored.
state.setAnimation(0, "events1", false);
}
}
});
setup("addAnimation with delay on empty track", // 22 setup("addAnimation with delay on empty track", // 22
expect(0, "start", 0, 0), // expect(0, "start", 0, 0), //

View File

@ -121,8 +121,12 @@ public class AnimationState {
float mix = current.alpha; float mix = current.alpha;
if (current.mixingFrom != null) { if (current.mixingFrom != null) {
mix *= current.mixTime / current.mixDuration; if (current.mixDuration == 0)
if (mix > 1) mix = 1; mix = 1;
else {
mix *= current.mixTime / current.mixDuration;
if (mix > 1) mix = 1;
}
applyMixingFrom(current.mixingFrom, skeleton, mix); applyMixingFrom(current.mixingFrom, skeleton, mix);
if (mix == 1) { if (mix == 1) {
queue.end(current.mixingFrom); queue.end(current.mixingFrom);
@ -254,15 +258,12 @@ public class AnimationState {
queue.interrupt(current); queue.interrupt(current);
if (entry.mixDuration > 0) { // If a mix is in progress, mix from the closest animation.
// If a mix is in progress, mix from the closest animation. if (mixingFrom != null && current.mixTime / current.mixDuration < 0.5f) {
if (mixingFrom != null && current.mixTime / current.mixDuration < 0.5f) { entry.mixingFrom = mixingFrom;
entry.mixingFrom = mixingFrom; mixingFrom = current;
mixingFrom = current;
} else
entry.mixingFrom = current;
} else } else
queue.end(current); entry.mixingFrom = current;
if (mixingFrom != null) queue.end(mixingFrom); if (mixingFrom != null) queue.end(mixingFrom);
} }
@ -339,16 +340,17 @@ public class AnimationState {
if (animation == null) throw new IllegalArgumentException("animation cannot be null."); if (animation == null) throw new IllegalArgumentException("animation cannot be null.");
TrackEntry current = expandToIndex(trackIndex); TrackEntry current = expandToIndex(trackIndex);
TrackEntry entry = trackEntry(trackIndex, animation, loop, current); TrackEntry entry = trackEntry(trackIndex, animation, loop, current);
if (current != null) { if (current == null)
setCurrent(trackIndex, entry);
else {
freeAll(current.next); freeAll(current.next);
if (current.trackLast == -1) // If current was never applied, don't mix from it, just replace it. if (current.trackLast == -1) // If current was never applied, replace it.
setCurrent(trackIndex, entry); setCurrent(trackIndex, entry);
else { else {
current.next = entry; current.next = entry;
entry.delay = current.trackLast; entry.delay = current.trackLast;
} }
} else }
setCurrent(trackIndex, entry);
return entry; return entry;
} }
@ -375,7 +377,9 @@ public class AnimationState {
TrackEntry entry = trackEntry(trackIndex, animation, loop, last); TrackEntry entry = trackEntry(trackIndex, animation, loop, last);
if (last != null) { if (last == null)
setCurrent(trackIndex, entry);
else {
last.next = entry; last.next = entry;
if (delay <= 0) { if (delay <= 0) {
float duration = last.animationEnd - last.animationStart; float duration = last.animationEnd - last.animationStart;
@ -384,8 +388,7 @@ public class AnimationState {
else else
delay = 0; delay = 0;
} }
} else }
setCurrent(trackIndex, entry);
entry.delay = delay; entry.delay = delay;
return entry; return entry;