diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AnimationStateTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AnimationStateTest.java index 0dea4cf96..6b3f7fd94 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AnimationStateTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AnimationStateTest.java @@ -372,7 +372,7 @@ public class AnimationStateTest { state.setAnimation(0, "events1", true); run(0.1f, 4, null); - setup("not looping, update past animation 0 duration", // 12 + setup("not looping, track end past animation 0 duration", // 12 expect(0, "start", 0, 0), // expect(0, "event 0", 0, 0), // expect(0, "event 14", 0.5f, 0.5f), // @@ -655,6 +655,20 @@ public class AnimationStateTest { } }); + setup("resetTrack", // 24 + expect(0, "start", 0, 0), // + expect(0, "event 0", 0, 0), // + expect(0, "event 14", 0.5f, 0.5f), // + expect(0, "end", 0.7f, 0.8f), // + expect(0, "dispose", 0.7f, 0.8f) // + ); + state.addAnimation(0, "events1", false, 0); + run(0.1f, 10, new TestListener() { + public void frame (float time) { + if (MathUtils.isEqual(time, 0.7f)) state.resetTrack(0); + } + }); + System.out.println("AnimationState tests passed."); } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java index 0965a2144..f48055a9b 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -43,6 +43,8 @@ import com.esotericsoftware.spine.Animation.Timeline; /** Stores state for applying one or more animations over time and automatically mixes (crossfades) when animations change. */ public class AnimationState { + static private final Animation emptyAnimation = new Animation("", new Array(0), 0); + private AnimationStateData data; private final Array tracks = new Array(); private final Array events = new Array(); @@ -236,6 +238,7 @@ public class AnimationState { events.clear(); } + /** Removes all animations from all tracks, leaving skeletons in their last pose. */ public void clearTracks () { for (int i = 0, n = tracks.size; i < n; i++) { TrackEntry current = tracks.get(i); @@ -245,7 +248,7 @@ public class AnimationState { queue.drain(); } - // BOZO - This leaves the skeleton in the last pose, with no easy way of resetting. + /** Removes all animations from the track, leaving skeletons in their last pose. */ public void clearTrack (int trackIndex) { if (trackIndex >= tracks.size) return; TrackEntry current = tracks.get(trackIndex); @@ -268,6 +271,32 @@ public class AnimationState { tracks.set(current.trackIndex, null); } + /** Removes all queued animations for all tracks and sets track entries which mix out the current animations, so any changes + * the animations have made to skeletons are reverted to the setup pose. */ + public void resetTracks () { + for (int i = 0, n = tracks.size; i < n; i++) { + TrackEntry current = tracks.get(i); + if (current != null) resetTrack(current); + } + queue.drain(); + } + + /** Removes all queued animations and sets a track entry which mixes out the current animation, so any changes the animation + * has made to skeletons are reverted to the setup pose. */ + public void resetTrack (int trackIndex) { + if (trackIndex >= tracks.size) return; + TrackEntry current = tracks.get(trackIndex); + if (current == null) return; + resetTrack(current); + queue.drain(); + } + + private void resetTrack (TrackEntry current) { + TrackEntry entry = trackEntry(current.trackIndex, emptyAnimation, false, current); + current.trackTime = 0; + setCurrent(current.trackIndex, entry); + } + /** @param entry May be null. */ private void disposeNext (TrackEntry entry) { TrackEntry next = entry.next; diff --git a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java index 3c8d0528a..5fd32bad3 100644 --- a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java +++ b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java @@ -488,7 +488,7 @@ public class SkeletonViewer extends ApplicationAdapter { if (state != null) { String name = animationList.getSelected(); if (name == null) - state.clearTrack(0); + state.resetTrack(0); else setAnimation(); }