From 127c0fbbf51cb1e936ed3efead48936dee5d581d Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 18 Aug 2016 15:17:13 +0200 Subject: [PATCH] AnimationState, added draw order threshold. --- .../spine/AnimationStateTest.java | 4 +- .../spine/AnimationState.java | 54 +++++++++++++------ 2 files changed, 40 insertions(+), 18 deletions(-) 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 28bce52aa..092d61c46 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 @@ -290,7 +290,7 @@ public class AnimationStateTest { expect(1, "complete 1", 1, 1.4f), // expect(1, "end", 1, 1.5f) // ); - state.setDefaultEventThreshold(0.5f); + state.setEventThreshold(0.5f); state.setAnimation(0, "events1", false); state.addAnimation(0, "events2", false, 0.4f); run(0.1f, 1000); @@ -315,7 +315,7 @@ public class AnimationStateTest { expect(1, "complete 1", 1, 1.4f), // expect(1, "end", 1, 1.5f) // ); - state.setDefaultEventThreshold(1); + state.setEventThreshold(1); state.setAnimation(0, "events1", false); state.addAnimation(0, "events2", false, 0.4f); run(0.1f, 1000); 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 0e393346a..988a6e0e7 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -36,6 +36,7 @@ import com.badlogic.gdx.utils.IntArray; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Pool.Poolable; import com.esotericsoftware.spine.Animation.AttachmentTimeline; +import com.esotericsoftware.spine.Animation.DrawOrderTimeline; import com.esotericsoftware.spine.Animation.Timeline; /** Stores state for an animation and automatically mixes between animations. */ @@ -46,7 +47,7 @@ public class AnimationState { private final EventQueue queue = new EventQueue(); final Array listeners = new Array(); private float timeScale = 1; - private float defaultEventThreshold, defaultAttachmentThreshold; + private float eventThreshold, attachmentThreshold, drawOrderThreshold; final Pool trackEntryPool = new Pool() { protected Object newObject () { @@ -141,13 +142,15 @@ public class AnimationState { Array events = mix < previous.eventThreshold ? this.events : null; Array timelines = animation.timelines; - if (mix < previous.attachmentThreshold) { + boolean attachments = mix < previous.attachmentThreshold, drawOrder = mix < previous.drawOrderThreshold; + if (attachments && drawOrder) { for (int i = 0, n = timelines.size; i < n; i++) timelines.get(i).apply(skeleton, lastTime, time, events, alpha); } else { for (int i = 0, n = timelines.size; i < n; i++) { Timeline timeline = timelines.get(i); - if (timeline instanceof AttachmentTimeline) continue; + if (!attachments && timeline instanceof AttachmentTimeline) continue; + if (!drawOrder && timeline instanceof DrawOrderTimeline) continue; timeline.apply(skeleton, lastTime, time, events, alpha); } } @@ -262,8 +265,9 @@ public class AnimationState { entry.animation = animation; entry.loop = loop; entry.endTime = animation.getDuration(); - entry.eventThreshold = defaultEventThreshold; - entry.attachmentThreshold = defaultAttachmentThreshold; + entry.eventThreshold = eventThreshold; + entry.attachmentThreshold = attachmentThreshold; + entry.drawOrderThreshold = drawOrderThreshold; setCurrent(trackIndex, entry); queue.drain(); @@ -284,8 +288,9 @@ public class AnimationState { entry.animation = animation; entry.loop = loop; entry.endTime = animation.getDuration(); - entry.eventThreshold = defaultEventThreshold; - entry.attachmentThreshold = defaultAttachmentThreshold; + entry.eventThreshold = eventThreshold; + entry.attachmentThreshold = attachmentThreshold; + entry.drawOrderThreshold = drawOrderThreshold; TrackEntry last = expandToIndex(trackIndex); if (last != null) { @@ -339,20 +344,28 @@ public class AnimationState { this.timeScale = timeScale; } - public float getDefaultEventThreshold () { - return defaultEventThreshold; + public float getEventThreshold () { + return eventThreshold; } - public void setDefaultEventThreshold (float defaultEventThreshold) { - this.defaultEventThreshold = defaultEventThreshold; + public void setEventThreshold (float eventThreshold) { + this.eventThreshold = eventThreshold; } - public float getDefaultAttachmentThreshold () { - return defaultAttachmentThreshold; + public float getAttachmentThreshold () { + return attachmentThreshold; } - public void setDefaultAttachmentThreshold (float defaultAttachmentThreshold) { - this.defaultAttachmentThreshold = defaultAttachmentThreshold; + public void setAttachmentThreshold (float attachmentThreshold) { + this.attachmentThreshold = attachmentThreshold; + } + + public float getDrawOrderThreshold () { + return drawOrderThreshold; + } + + public void setDrawOrderThreshold (float drawOrderThreshold) { + this.drawOrderThreshold = drawOrderThreshold; } public AnimationStateData getData () { @@ -385,7 +398,8 @@ public class AnimationState { TrackEntry next, previous; Animation animation; boolean loop; - float delay, time, lastTime = -1, endTime, timeScale = 1, eventThreshold, attachmentThreshold; + float delay, time, lastTime = -1, endTime, timeScale = 1; + float eventThreshold, attachmentThreshold, drawOrderThreshold; float mixTime, mixDuration; AnimationStateListener listener; float alpha = 1; @@ -488,6 +502,14 @@ public class AnimationState { this.attachmentThreshold = attachmentThreshold; } + public float getDrawOrderThreshold () { + return drawOrderThreshold; + } + + public void setDrawOrderThreshold (float drawOrderThreshold) { + this.drawOrderThreshold = drawOrderThreshold; + } + public TrackEntry getNext () { return next; }