apply speed to both time and total time fixes #3927 https://github.com/rive-app/rive/issues/3927 i did it once by changing how to determine the work end area, but then compared to flutter, which was doing this by changing how advance works. which is probably better. Diffs= bd567e2ba apply speed to both time and total time
diff --git a/.rive_head b/.rive_head index 2cc4a4c..b6e350d 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -291a3a02bce12a2c92a456f6a71ad3a410162f0f +bd567e2ba93201acb747fd1b0929896c31c84eb4
diff --git a/src/animation/linear_animation_instance.cpp b/src/animation/linear_animation_instance.cpp index 3a7b1c5..ccd31ae 100644 --- a/src/animation/linear_animation_instance.cpp +++ b/src/animation/linear_animation_instance.cpp
@@ -49,9 +49,11 @@ bool LinearAnimationInstance::advance(float elapsedSeconds) { const LinearAnimation& animation = *m_Animation; - m_Time += elapsedSeconds * animation.speed() * m_Direction; + float deltaSeconds = elapsedSeconds * animation.speed(); + + m_Time += deltaSeconds * m_Direction; m_LastTotalTime = m_TotalTime; - m_TotalTime += elapsedSeconds; + m_TotalTime += deltaSeconds; int fps = animation.fps();
diff --git a/test/linear_animation_instance_test.cpp b/test/linear_animation_instance_test.cpp index d9b0519..07f06ad 100644 --- a/test/linear_animation_instance_test.cpp +++ b/test/linear_animation_instance_test.cpp
@@ -40,6 +40,33 @@ delete linearAnimation; } +TEST_CASE("LinearAnimationInstance speed", "[animation]") +{ + rive::NoOpFactory emptyFactory; + // For each of these tests, we cons up a dummy artboard/instance + // just to make the animations happy. + rive::Artboard ab(&emptyFactory); + auto abi = ab.instance(); + + rive::LinearAnimation* linearAnimation = new rive::LinearAnimation(); + // duration in seconds is 5 + linearAnimation->duration(10); + linearAnimation->fps(2); + linearAnimation->speed(.5); + + rive::LinearAnimationInstance* linearAnimationInstance = + new rive::LinearAnimationInstance(linearAnimation, abi.get()); + + // play from beginning. + bool continuePlaying = linearAnimationInstance->advance(2.0); + REQUIRE(continuePlaying == true); + REQUIRE(linearAnimationInstance->time() == 1.0f); + REQUIRE(linearAnimationInstance->totalTime() == 1.0f); + + delete linearAnimationInstance; + delete linearAnimation; +} + TEST_CASE("LinearAnimationInstance oneShot <-", "[animation]") { rive::NoOpFactory emptyFactory;