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

This commit is contained in:
Mario Zechner 2024-12-09 14:56:24 +01:00
parent d1117b8248
commit 9bd964514d
2 changed files with 16 additions and 0 deletions

View File

@ -806,6 +806,20 @@ bool AnimationState::updateMixingFrom(TrackEntry *to, float delta) {
return finished; 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; from->_trackTime += delta * from->_timeScale;
to->_mixTime += delta; to->_mixTime += delta;

View File

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