diff --git a/spine-c/include/spine/AnimationState.h b/spine-c/include/spine/AnimationState.h index 2dc163ced..8e13f18fe 100644 --- a/spine-c/include/spine/AnimationState.h +++ b/spine-c/include/spine/AnimationState.h @@ -55,19 +55,19 @@ struct TrackEntry { TrackEntry* previous; Animation* animation; int/*bool*/loop; - float delay, time, lastTime, endTime; + float delay, time, lastTime, endTime, timeScale; AnimationStateListener listener; float mixTime, mixDuration; }; struct AnimationState { AnimationStateData* const data; + float timeScale; + AnimationStateListener listener; + void* context; int trackCount; TrackEntry** tracks; - - AnimationStateListener listener; - void* context; }; /* @param data May be 0 for no mixing. */ diff --git a/spine-c/src/spine/AnimationState.c b/spine-c/src/spine/AnimationState.c index 50076935b..93e78c4a6 100644 --- a/spine-c/src/spine/AnimationState.c +++ b/spine-c/src/spine/AnimationState.c @@ -43,6 +43,7 @@ TrackEntry* _TrackEntry_create () { TrackEntry* entry = NEW(TrackEntry); + entry->timeScale = 1; return entry; } @@ -71,6 +72,7 @@ AnimationState* AnimationState_create (AnimationStateData* data) { _AnimationState* internal = NEW(_AnimationState); AnimationState* self = SUPER(internal); internal->events = MALLOC(Event*, 64); + self->timeScale = 1; CONST_CAST(AnimationStateData*, self->data) = data; return self; } @@ -89,6 +91,7 @@ void AnimationState_update (AnimationState* self, float delta) { TrackEntry* current = self->tracks[i]; if (!current) continue; + delta *= self->timeScale * current->timeScale; time = current->time + delta; endTime = current->endTime; diff --git a/spine-csharp/src/AnimationState.cs b/spine-csharp/src/AnimationState.cs index c2cd50381..bf11f9282 100644 --- a/spine-csharp/src/AnimationState.cs +++ b/spine-csharp/src/AnimationState.cs @@ -40,8 +40,10 @@ namespace Spine { private AnimationStateData data; private List tracks = new List(); private List events = new List(); + private float timeScale = 1; public AnimationStateData Data { get { return data; } } + public float TimeScale { get { return timeScale; } set { timeScale = value; } } public event EventHandler Start; public event EventHandler End; @@ -58,6 +60,7 @@ namespace Spine { TrackEntry current = tracks[i]; if (current == null) continue; + delta *= timeScale * current.timeScale; float time = current.time + delta; float endTime = current.endTime; @@ -264,21 +267,16 @@ namespace Spine { internal TrackEntry next, previous; internal Animation animation; internal bool loop; - internal float delay, time, lastTime, endTime; + internal float delay, time, lastTime, endTime, timeScale = 1; internal float mixTime, mixDuration; public Animation Animation { get { return animation; } } - public bool Loop { get { return loop; } set { loop = value; } } public float Delay { get { return delay; } set { delay = value; } } - public float EndTime { get { return EndTime; } set { EndTime = value; } } - - public float Time { - get { return time; } - set { - time = value; - if (lastTime < value) lastTime = value; - } - } + public float Time { get { return time; } set { time = value; } } + public float LastTime { get { return lastTime; } set { lastTime = value; } } + public float EndTime { get { return endTime; } set { endTime = value; } } + public float TimeScale { get { return timeScale; } set { timeScale = value; } } + public bool Loop { get { return loop; } set { loop = value; } } public event EventHandler Start; public event EventHandler End; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java index fdd634185..d548dcb51 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -43,6 +43,7 @@ public class AnimationState { private Array tracks = new Array(); private final Array events = new Array(); private final Array listeners = new Array(); + private float timeScale; public AnimationState (AnimationStateData data) { if (data == null) throw new IllegalArgumentException("data cannot be null."); @@ -54,6 +55,7 @@ public class AnimationState { TrackEntry current = tracks.get(i); if (current == null) continue; + delta *= timeScale * current.timeScale; float time = current.time + delta; float endTime = current.endTime; @@ -253,6 +255,14 @@ public class AnimationState { listeners.removeValue(listener, true); } + public float getTimeScale () { + return timeScale; + } + + public void setTimeScale (float timeScale) { + this.timeScale = timeScale; + } + public AnimationStateData getData () { return data; } @@ -273,14 +283,15 @@ public class AnimationState { TrackEntry next, previous; Animation animation; boolean loop; - float delay, time, lastTime, endTime; - AnimationStateListener listener; + float delay, time, lastTime, endTime, timeScale = 1; float mixTime, mixDuration; + AnimationStateListener listener; public void reset () { animation = null; listener = null; next = null; + timeScale = 1; } public Animation getAnimation () { @@ -339,6 +350,14 @@ public class AnimationState { this.lastTime = lastTime; } + public float getTimeScale () { + return timeScale; + } + + public void setTimeScale (float timeScale) { + this.timeScale = timeScale; + } + public TrackEntry getNext () { return next; }