Pārlūkot izejas kodu

[cpp] Port of commit 8d058fb: Improved AnimationState behavior when paused. See #2705

Mario Zechner 9 mēneši atpakaļ
vecāks
revīzija
9bd964514d

+ 14 - 0
spine-cpp/spine-cpp/src/spine/AnimationState.cpp

@@ -806,6 +806,20 @@ bool AnimationState::updateMixingFrom(TrackEntry *to, float delta) {
 		return finished;
 	}
 
+	if (to->_nextTrackLast != -1) { // The from entry was applied at least once.
+			bool discard = to->_mixTime == 0 && from->_mixTime == 0; // Discard the from entry when neither have advanced yet.
+			if (to->_mixTime >= to->_mixDuration || discard) {
+				// Require totalAlpha == 0 to ensure mixing is complete or the transition is a single frame or discarded.
+				if (from->_totalAlpha == 0 || to->_mixDuration == 0 || discard) {
+					to->_mixingFrom = from->_mixingFrom;
+					if (from->_mixingFrom) from->_mixingFrom->_mixingTo = to;
+					to->_interruptAlpha = from->_interruptAlpha;
+					_queue->end(from);
+				}
+				return finished;
+			}
+		}
+
 	from->_trackTime += delta * from->_timeScale;
 	to->_mixTime += delta;
 

+ 2 - 0
spine-glfw/example/main.cpp

@@ -52,8 +52,10 @@ int main() {
 	// Create an AnimationState to drive animations on the skeleton. Set the "portal" animation
 	// on track with index 0.
 	AnimationStateData animationStateData(skeletonData);
+	animationStateData.setDefaultMix(0.2f);
 	AnimationState animationState(&animationStateData);
 	animationState.setAnimation(0, "portal", true);
+	animationState.addAnimation(0, "run", true, 0);
 
 	// Create the renderer and set the viewport size to match the window size. This sets up a
 	// pixel perfect orthogonal projection for 2D rendering.