Эх сурвалжийг харах

[haxe] port of commit 4a351ce: Fixed delay being negative, causing the track time to jump. See #2837.

Davide Tantillo 4 сар өмнө
parent
commit
24529f5cd1

+ 3 - 4
spine-haxe/spine-haxe/spine/animation/AnimationState.hx

@@ -594,11 +594,11 @@ class AnimationState {
 		if (last == null) {
 			setCurrent(trackIndex, entry, true);
 			queue.drain();
+			if (delay < 0) delay = 0;
 		} else {
 			last.next = entry;
 			entry.previous = last;
-			if (delay <= 0)
-				delay += last.getTrackComplete() - entry.mixDuration;
+			if (delay <= 0) delay = Math.max(delay + last.getTrackComplete() - entry.mixDuration, 0);
 		}
 
 		entry.delay = delay;
@@ -614,8 +614,7 @@ class AnimationState {
 
 	public function addEmptyAnimation(trackIndex:Int, mixDuration:Float, delay:Float):TrackEntry {
 		var entry:TrackEntry = addAnimation(trackIndex, emptyAnimation, false, delay);
-		if (delay <= 0)
-			entry.delay += entry.mixDuration - mixDuration;
+		if (delay <= 0) entry.delay = Math.max(entry.delay + entry.mixDuration - mixDuration, 0);
 		entry.mixDuration = mixDuration;
 		entry.trackEnd = mixDuration;
 		return entry;

+ 29 - 10
spine-haxe/spine-haxe/spine/animation/TrackEntry.hx

@@ -56,7 +56,20 @@ class TrackEntry implements Poolable {
 	public var animationEnd:Float = 0;
 	public var animationLast:Float = 0;
 	public var nextAnimationLast:Float = 0;
-	public var delay:Float = 0;
+
+	/** Seconds to postpone playing the animation. Must be >= 0. When this track entry is the current track entry,
+	* <code>delay</code> postpones incrementing the {@link #getTrackTime()}. When this track entry is queued,
+	* <code>delay</code> is the time from the start of the previous animation to when this track entry will become the current
+	* track entry (ie when the previous track entry {@link TrackEntry#getTrackTime()} >= this track entry's
+	* <code>delay</code>).
+	* <p>
+	* {@link #getTimeScale()} affects the delay.
+	* <p>
+	* When passing <code>delay</code> <= 0 to {@link AnimationState#addAnimation(int, Animation, boolean, float)} this
+	* <code>delay</code> is set using a mix duration from {@link AnimationStateData}. To change the {@link #getMixDuration()}
+	* afterward, use {@link #setMixDuration(float, float)} so this <code>delay</code> is adjusted. */
+	public var delay(default, set):Float = 0;
+
 	public var trackTime:Float = 0;
 	public var trackLast:Float = 0;
 	public var nextTrackLast:Float = 0;
@@ -64,7 +77,7 @@ class TrackEntry implements Poolable {
 	public var timeScale:Float = 0;
 	public var alpha:Float = 0;
 	public var mixTime:Float = 0;
-	@:isVar public var mixDuration(get, set):Float = 0;
+	public var mixDuration:Float = 0;
 	public var interruptAlpha:Float = 0;
 	public var totalAlpha:Float = 0;
 	public var mixBlend:MixBlend = MixBlend.replace;
@@ -73,14 +86,9 @@ class TrackEntry implements Poolable {
 	public var timelinesRotation:Array<Float> = new Array<Float>();
 	public var shortestRotation = false;
 
-	function get_mixDuration():Float {
-		return mixDuration;
-	}
-
-	function set_mixDuration(mixDuration:Float):Float {
-		this.mixDuration = mixDuration;
-		if (previous != null && delay <= 0) delay += previous.getTrackComplete() - mixDuration;
-		return mixDuration;
+	function set_delay(delay:Float):Float {
+		if (delay < 0) throw new SpineException("delay must be >= 0.");
+		return this.delay = delay;
 	}
 
 	public function new() {}
@@ -142,4 +150,15 @@ class TrackEntry implements Poolable {
 	public function resetRotationDirection():Void {
 		timelinesRotation.resize(0);
 	}
+
+	public function setMixDurationWithDelay(mixDuration:Float):Float {
+		this.mixDuration = mixDuration;
+		if (delay <= 0) {
+			if (this.previous != null)
+				delay = Math.max(delay + this.previous.getTrackComplete() - mixDuration, 0);
+			else
+				delay = 0;
+		}
+		return mixDuration;
+	}
 }