Browse Source

Allow a track to mix with the track below.

http://esotericsoftware.com/forum/viewtopic.php?f=7&t=2248
NathanSweet 11 years ago
parent
commit
aff250daf4

+ 7 - 4
spine-as3/spine-as3/src/spine/animation/AnimationState.as

@@ -83,14 +83,17 @@ public class AnimationState {
 			if (!loop && time > endTime) time = endTime;
 			
 			var previous:TrackEntry = current.previous;
-			if (!previous)
-				current.animation.apply(skeleton, current.lastTime, time, loop, _events);
-			else {
+			if (!previous) {
+				if (current.mix == 1)
+					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;
 				if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
 				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) {
 					alpha = 1;
 					current.previous = null;

+ 1 - 1
spine-as3/spine-as3/src/spine/animation/TrackEntry.as

@@ -36,7 +36,7 @@ public class TrackEntry {
 	public var animation:Animation;
 	public var loop:Boolean;
 	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 function toString () : String {

+ 1 - 1
spine-c/include/spine/AnimationState.h

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

+ 11 - 4
spine-c/src/spine/AnimationState.c

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

+ 10 - 6
spine-csharp/src/AnimationState.cs

@@ -102,14 +102,17 @@ namespace Spine {
 				if (!loop && time > current.endTime) time = current.endTime;
 
 				TrackEntry previous = current.previous;
-				if (previous == null)
-					current.animation.Apply(skeleton, current.lastTime, time, loop, events);
-				else {
+				if (previous == null) {
+					if (current.mix == 1)
+						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;
 					if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
 					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) {
 						alpha = 1;
 						current.previous = null;
@@ -252,7 +255,7 @@ namespace Spine {
 		internal Animation animation;
 		internal bool loop;
 		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 float Delay { get { return delay; } set { delay = value; } }
@@ -260,8 +263,9 @@ namespace Spine {
 		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 float Mix { get { return mix; } set { mix = value; } }
 		public bool Loop { get { return loop; } set { loop = value; } }
-		
+
 		public event AnimationState.StartEndDelegate Start;
 		public event AnimationState.StartEndDelegate End;
 		public event AnimationState.EventDelegate Event;

+ 8 - 5
spine-js/spine.js

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

+ 16 - 4
spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java

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

+ 7 - 3
spine-lua/AnimationState.lua

@@ -103,13 +103,17 @@ function AnimationState.new (data)
 
 				local previous = current.previous
 				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
 					local previousTime = previous.time
 					if not previous.loop and previousTime > previous.endTime then previousTime = previous.endTime end
 					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
 						alpha = 1
 						current.previous = nil
@@ -235,7 +239,7 @@ function AnimationState.TrackEntry.new (data)
 		loop = false,
 		delay = 0, time = 0, lastTime = -1, endTime = 0,
 		timeScale = 1,
-		mixTime = 0, mixDuration = 0,
+		mixTime = 0, mixDuration = 0, mix = 0,
 		onStart = nil, onEnd = nil, onComplete = nil, onEvent = nil
 	}
 	return self