Skip to content

Commit

Permalink
negative speed fix
Browse files Browse the repository at this point in the history
negative speed states wouldn't play the animation if it didn't have transition duration or exit time.
this PR fixes it by taking into account the speed multiplier when evaluating if the animation still has frames to play.

Diffs=
0bc446fad negative speed fix (#6982)

Co-authored-by: hernan <hernan@rive.app>
  • Loading branch information
bodymovin and bodymovin committed Apr 8, 2024
1 parent a96799e commit 097c1fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f832e26172cfbd11d52114ebb667e13418a5b1cd
0bc446fad2a568a7088fdaa122af0de2de1dc940
7 changes: 7 additions & 0 deletions include/rive/animation/linear_animation_instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ class LinearAnimationInstance : public Scene
(directedSpeed() < 0 && m_time > m_animation->startSeconds());
}

bool keepGoing(float speedMultiplier) const
{
return this->loopValue() != static_cast<int>(rive::Loop::oneShot) ||
(directedSpeed() * speedMultiplier > 0 && m_time < m_animation->endSeconds()) ||
(directedSpeed() * speedMultiplier < 0 && m_time > m_animation->startSeconds());
}

float totalTime() const { return m_totalTime; }
float lastTotalTime() const { return m_lastTotalTime; }
float spilledTime() const { return m_spilledTime; }
Expand Down
4 changes: 2 additions & 2 deletions src/animation/linear_animation_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool LinearAnimationInstance::advance(float elapsedSeconds, KeyedCallbackReporte
// NOTE:
// do not track spilled time, if our one shot loop is already completed.
// stop gap before we move spilled tracking into state machine logic.
bool killSpilledTime = !this->keepGoing();
bool killSpilledTime = !this->keepGoing(elapsedSeconds);

float lastTime = m_time;
m_time += deltaSeconds;
Expand Down Expand Up @@ -165,7 +165,7 @@ bool LinearAnimationInstance::advance(float elapsedSeconds, KeyedCallbackReporte
}

m_didLoop = didLoop;
return this->keepGoing();
return this->keepGoing(elapsedSeconds);
}

void LinearAnimationInstance::time(float value)
Expand Down

0 comments on commit 097c1fe

Please sign in to comment.