mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Added resetTrack.
This commit is contained in:
parent
3c57c03952
commit
bc05861a0c
@ -372,7 +372,7 @@ public class AnimationStateTest {
|
|||||||
state.setAnimation(0, "events1", true);
|
state.setAnimation(0, "events1", true);
|
||||||
run(0.1f, 4, null);
|
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, "start", 0, 0), //
|
||||||
expect(0, "event 0", 0, 0), //
|
expect(0, "event 0", 0, 0), //
|
||||||
expect(0, "event 14", 0.5f, 0.5f), //
|
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.");
|
System.out.println("AnimationState tests passed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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. */
|
/** Stores state for applying one or more animations over time and automatically mixes (crossfades) when animations change. */
|
||||||
public class AnimationState {
|
public class AnimationState {
|
||||||
|
static private final Animation emptyAnimation = new Animation("<empty>", new Array(0), 0);
|
||||||
|
|
||||||
private AnimationStateData data;
|
private AnimationStateData data;
|
||||||
private final Array<TrackEntry> tracks = new Array();
|
private final Array<TrackEntry> tracks = new Array();
|
||||||
private final Array<Event> events = new Array();
|
private final Array<Event> events = new Array();
|
||||||
@ -236,6 +238,7 @@ public class AnimationState {
|
|||||||
events.clear();
|
events.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Removes all animations from all tracks, leaving skeletons in their last pose. */
|
||||||
public void clearTracks () {
|
public void clearTracks () {
|
||||||
for (int i = 0, n = tracks.size; i < n; i++) {
|
for (int i = 0, n = tracks.size; i < n; i++) {
|
||||||
TrackEntry current = tracks.get(i);
|
TrackEntry current = tracks.get(i);
|
||||||
@ -245,7 +248,7 @@ public class AnimationState {
|
|||||||
queue.drain();
|
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) {
|
public void clearTrack (int trackIndex) {
|
||||||
if (trackIndex >= tracks.size) return;
|
if (trackIndex >= tracks.size) return;
|
||||||
TrackEntry current = tracks.get(trackIndex);
|
TrackEntry current = tracks.get(trackIndex);
|
||||||
@ -268,6 +271,32 @@ public class AnimationState {
|
|||||||
tracks.set(current.trackIndex, null);
|
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. */
|
/** @param entry May be null. */
|
||||||
private void disposeNext (TrackEntry entry) {
|
private void disposeNext (TrackEntry entry) {
|
||||||
TrackEntry next = entry.next;
|
TrackEntry next = entry.next;
|
||||||
|
|||||||
@ -488,7 +488,7 @@ public class SkeletonViewer extends ApplicationAdapter {
|
|||||||
if (state != null) {
|
if (state != null) {
|
||||||
String name = animationList.getSelected();
|
String name = animationList.getSelected();
|
||||||
if (name == null)
|
if (name == null)
|
||||||
state.clearTrack(0);
|
state.resetTrack(0);
|
||||||
else
|
else
|
||||||
setAnimation();
|
setAnimation();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user