Allow a track to mix with the track below.

http://esotericsoftware.com/forum/viewtopic.php?f=7&t=2248
This commit is contained in:
NathanSweet 2014-03-09 12:06:36 +01:00
parent 3424f31f53
commit aff250daf4
8 changed files with 61 additions and 28 deletions

View File

@ -83,14 +83,17 @@ public class AnimationState {
if (!loop && time > endTime) time = endTime; if (!loop && time > endTime) time = endTime;
var previous:TrackEntry = current.previous; var previous:TrackEntry = current.previous;
if (!previous) if (!previous) {
current.animation.apply(skeleton, current.lastTime, time, loop, _events); if (current.mix == 1)
else { current.animation.apply(skeleton, current.lastTime, time, loop, _events);
else
current.animation.mix(skeleton, current.lastTime, time, loop, _events, current.mix);
} else {
var previousTime:Number = previous.time; var previousTime:Number = previous.time;
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime; if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null); previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null);
var alpha:Number = current.mixTime / current.mixDuration; var alpha:Number = current.mixTime / current.mixDuration * current.mix;
if (alpha >= 1) { if (alpha >= 1) {
alpha = 1; alpha = 1;
current.previous = null; current.previous = null;

View File

@ -36,7 +36,7 @@ public class TrackEntry {
public var animation:Animation; public var animation:Animation;
public var loop:Boolean; public var loop:Boolean;
public var delay:Number, time:Number = 0, lastTime:Number = -1, endTime:Number, timeScale:Number = 1; public var delay:Number, time:Number = 0, lastTime:Number = -1, endTime:Number, timeScale:Number = 1;
internal var mixTime:Number, mixDuration:Number; internal var mixTime:Number, mixDuration:Number, mix:Number = 1;
public var onStart:Function, onEnd:Function, onComplete:Function, onEvent:Function; public var onStart:Function, onEnd:Function, onComplete:Function, onEvent:Function;
public function toString () : String { public function toString () : String {

View File

@ -54,7 +54,7 @@ struct spTrackEntry {
int/*bool*/loop; int/*bool*/loop;
float delay, time, lastTime, endTime, timeScale; float delay, time, lastTime, endTime, timeScale;
spAnimationStateListener listener; spAnimationStateListener listener;
float mixTime, mixDuration; float mixTime, mixDuration, mix;
}; };
struct spAnimationState { struct spAnimationState {

View File

@ -39,6 +39,7 @@ spTrackEntry* _spTrackEntry_create () {
spTrackEntry* entry = NEW(spTrackEntry); spTrackEntry* entry = NEW(spTrackEntry);
entry->timeScale = 1; entry->timeScale = 1;
entry->lastTime = -1; entry->lastTime = -1;
entry->mix = 1;
return entry; return entry;
} }
@ -124,9 +125,15 @@ void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
previous = current->previous; previous = current->previous;
if (!previous) { if (!previous) {
spAnimation_apply(current->animation, skeleton, current->lastTime, time, current->loop, internal->events, &eventCount); if (current->mix == 1) {
spAnimation_apply(current->animation, skeleton, current->lastTime, time,
current->loop, internal->events, &eventCount);
} else {
spAnimation_mix(current->animation, skeleton, current->lastTime, time,
current->loop, internal->events, &eventCount, current->mix);
}
} else { } else {
float alpha = current->mixTime / current->mixDuration; float alpha = current->mixTime / current->mixDuration * current->mix;
float previousTime = previous->time; float previousTime = previous->time;
if (!previous->loop && previousTime > previous->endTime) previousTime = previous->endTime; if (!previous->loop && previousTime > previous->endTime) previousTime = previous->endTime;
@ -137,8 +144,8 @@ void spAnimationState_apply (spAnimationState* self, spSkeleton* skeleton) {
_spTrackEntry_dispose(current->previous); _spTrackEntry_dispose(current->previous);
current->previous = 0; current->previous = 0;
} }
spAnimation_mix(current->animation, skeleton, current->lastTime, time, current->loop, internal->events, &eventCount, spAnimation_mix(current->animation, skeleton, current->lastTime, time,
alpha); current->loop, internal->events, &eventCount, alpha);
} }
for (ii = 0; ii < eventCount; ii++) { for (ii = 0; ii < eventCount; ii++) {

View File

@ -102,14 +102,17 @@ namespace Spine {
if (!loop && time > current.endTime) time = current.endTime; if (!loop && time > current.endTime) time = current.endTime;
TrackEntry previous = current.previous; TrackEntry previous = current.previous;
if (previous == null) if (previous == null) {
current.animation.Apply(skeleton, current.lastTime, time, loop, events); if (current.mix == 1)
else { current.animation.Apply(skeleton, current.lastTime, time, loop, events);
else
current.animation.Apply(skeleton, current.lastTime, time, loop, events, current.mix);
} else {
float previousTime = previous.time; float previousTime = previous.time;
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime; if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
previous.animation.Apply(skeleton, previousTime, previousTime, previous.loop, null); previous.animation.Apply(skeleton, previousTime, previousTime, previous.loop, null);
float alpha = current.mixTime / current.mixDuration; float alpha = current.mixTime / current.mixDuration * current.mix;
if (alpha >= 1) { if (alpha >= 1) {
alpha = 1; alpha = 1;
current.previous = null; current.previous = null;
@ -252,7 +255,7 @@ namespace Spine {
internal Animation animation; internal Animation animation;
internal bool loop; internal bool loop;
internal float delay, time, lastTime = -1, endTime, timeScale = 1; internal float delay, time, lastTime = -1, endTime, timeScale = 1;
internal float mixTime, mixDuration; internal float mixTime, mixDuration, mix = 1;
public Animation Animation { get { return animation; } } public Animation Animation { get { return animation; } }
public float Delay { get { return delay; } set { delay = value; } } public float Delay { get { return delay; } set { delay = value; } }
@ -260,6 +263,7 @@ namespace Spine {
public float LastTime { get { return lastTime; } set { lastTime = value; } } public float LastTime { get { return lastTime; } set { lastTime = value; } }
public float EndTime { get { return endTime; } set { endTime = value; } } public float EndTime { get { return endTime; } set { endTime = value; } }
public float TimeScale { get { return timeScale; } set { timeScale = value; } } public float TimeScale { get { return timeScale; } set { timeScale = value; } }
public float Mix { get { return mix; } set { mix = value; } }
public bool Loop { get { return loop; } set { loop = value; } } public bool Loop { get { return loop; } set { loop = value; } }
public event AnimationState.StartEndDelegate Start; public event AnimationState.StartEndDelegate Start;

View File

@ -946,7 +946,7 @@ spine.TrackEntry.prototype = {
loop: false, loop: false,
delay: 0, time: 0, lastTime: -1, endTime: 0, delay: 0, time: 0, lastTime: -1, endTime: 0,
timeScale: 1, timeScale: 1,
mixTime: 0, mixDuration: 0, mixTime: 0, mixDuration: 0, mix: 1,
onStart: null, onEnd: null, onComplete: null, onEvent: null onStart: null, onEnd: null, onComplete: null, onEvent: null
}; };
@ -997,14 +997,17 @@ spine.AnimationState.prototype = {
if (!loop && time > endTime) time = endTime; if (!loop && time > endTime) time = endTime;
var previous = current.previous; var previous = current.previous;
if (!previous) if (!previous) {
current.animation.apply(skeleton, current.lastTime, time, loop, this.events); if (current.mix == 1)
else { current.animation.apply(skeleton, current.lastTime, time, loop, this.events);
else
current.animation.mix(skeleton, current.lastTime, time, loop, this.events, current.mix);
} else {
var previousTime = previous.time; var previousTime = previous.time;
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime; if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null); previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null);
var alpha = current.mixTime / current.mixDuration; var alpha = current.mixTime / current.mixDuration * current.mix;
if (alpha >= 1) { if (alpha >= 1) {
alpha = 1; alpha = 1;
current.previous = null; current.previous = null;

View File

@ -91,14 +91,17 @@ public class AnimationState {
if (!loop && time > endTime) time = endTime; if (!loop && time > endTime) time = endTime;
TrackEntry previous = current.previous; TrackEntry previous = current.previous;
if (previous == null) if (previous == null) {
current.animation.apply(skeleton, lastTime, time, loop, events); if (current.mix == 1)
else { current.animation.apply(skeleton, lastTime, time, loop, events);
else
current.animation.mix(skeleton, lastTime, time, loop, events, current.mix);
} else {
float previousTime = previous.time; float previousTime = previous.time;
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime; if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null); previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null);
float alpha = current.mixTime / current.mixDuration; float alpha = current.mixTime / current.mixDuration * current.mix;
if (alpha >= 1) { if (alpha >= 1) {
alpha = 1; alpha = 1;
trackEntryPool.free(previous); trackEntryPool.free(previous);
@ -301,6 +304,7 @@ public class AnimationState {
float delay, time, lastTime, endTime, timeScale = 1; float delay, time, lastTime, endTime, timeScale = 1;
float mixTime, mixDuration; float mixTime, mixDuration;
AnimationStateListener listener; AnimationStateListener listener;
float mix = 1;
public void reset () { public void reset () {
next = null; next = null;
@ -368,6 +372,14 @@ public class AnimationState {
this.lastTime = lastTime; this.lastTime = lastTime;
} }
public float getMix () {
return mix;
}
public void setMix (float mix) {
this.mix = mix;
}
public float getTimeScale () { public float getTimeScale () {
return timeScale; return timeScale;
} }

View File

@ -103,13 +103,17 @@ function AnimationState.new (data)
local previous = current.previous local previous = current.previous
if not previous then if not previous then
current.animation:apply(skeleton, current.lastTime, time, loop, self.events) if current.mix == 1 then
current.animation:apply(skeleton, current.lastTime, time, loop, self.events)
else
current.animation:mix(skeleton, current.lastTime, time, loop, self.events, current.mix)
end
else else
local previousTime = previous.time local previousTime = previous.time
if not previous.loop and previousTime > previous.endTime then previousTime = previous.endTime end if not previous.loop and previousTime > previous.endTime then previousTime = previous.endTime end
previous.animation:apply(skeleton, previousTime, previousTime, previous.loop, nil) previous.animation:apply(skeleton, previousTime, previousTime, previous.loop, nil)
local alpha = current.mixTime / current.mixDuration local alpha = current.mixTime / current.mixDuration * current.mix
if alpha >= 1 then if alpha >= 1 then
alpha = 1 alpha = 1
current.previous = nil current.previous = nil
@ -235,7 +239,7 @@ function AnimationState.TrackEntry.new (data)
loop = false, loop = false,
delay = 0, time = 0, lastTime = -1, endTime = 0, delay = 0, time = 0, lastTime = -1, endTime = 0,
timeScale = 1, timeScale = 1,
mixTime = 0, mixDuration = 0, mixTime = 0, mixDuration = 0, mix = 0,
onStart = nil, onEnd = nil, onComplete = nil, onEvent = nil onStart = nil, onEnd = nil, onComplete = nil, onEvent = nil
} }
return self return self