allow negative speed Diffs= 89e38b700 allow negative speed (#4770)
diff --git a/.rive_head b/.rive_head index 4b15a4d..bca1be1 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -4d115b4c66d00b99bbfcd9a978b3b27d7f18b2d0 +89e38b700dce1e2328712c5258d2cd54b990b30b
diff --git a/src/animation/linear_animation_instance.cpp b/src/animation/linear_animation_instance.cpp index 3e7b361..e4f16be 100644 --- a/src/animation/linear_animation_instance.cpp +++ b/src/animation/linear_animation_instance.cpp
@@ -68,10 +68,11 @@ bool didLoop = false; m_SpilledTime = 0.0f; + int direction = speed() * m_Direction < 0 ? -1 : 1; switch (loop()) { case Loop::oneShot: - if (m_Direction == 1 && frames > end) + if (direction == 1 && frames > end) { keepGoing = false; m_SpilledTime = (frames - end) / fps; @@ -79,7 +80,7 @@ m_Time = frames / fps; didLoop = true; } - else if (m_Direction == -1 && frames < start) + else if (direction == -1 && frames < start) { keepGoing = false; m_SpilledTime = (start - frames) / fps; @@ -89,7 +90,7 @@ } break; case Loop::loop: - if (m_Direction == 1 && frames >= end) + if (direction == 1 && frames >= end) { m_SpilledTime = (frames - end) / fps; frames = m_Time * fps; @@ -98,9 +99,8 @@ m_Time = frames / fps; didLoop = true; } - else if (m_Direction == -1 && frames <= start) + else if (direction == -1 && frames <= start) { - m_SpilledTime = (start - frames) / fps; frames = m_Time * fps; frames = end - std::abs(std::fmod(start - frames, (float)range)); @@ -111,18 +111,18 @@ case Loop::pingPong: while (true) { - if (m_Direction == 1 && frames >= end) + if (direction == 1 && frames >= end) { m_SpilledTime = (frames - end) / fps; - m_Direction = -1; + m_Direction *= -1; frames = end + (end - frames); m_Time = frames / fps; didLoop = true; } - else if (m_Direction == -1 && frames < start) + else if (direction == -1 && frames < start) { m_SpilledTime = (start - frames) / fps; - m_Direction = 1; + m_Direction *= -1; frames = start + (start - frames); m_Time = frames / fps; didLoop = true;