From 9c08c351b80197fd485e438b175a8293e681686d Mon Sep 17 00:00:00 2001 From: viktorljung Date: Wed, 10 Feb 2016 23:33:23 +0100 Subject: [PATCH] fixed reverse Animation looping --- src/Engine/Rendering/AnimationSystem.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 3df502c4..48681e6e 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -31,20 +31,27 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt; - if (!(bool)animationComponent["Loop" + std::to_string(i)] && glm::abs(nextTime) > animation->Duration) { - (double&)animationComponent["Time" + std::to_string(i)] = glm::sign(nextTime) * animation->Duration; + if (!(bool)animationComponent["Loop" + std::to_string(i)]) { + if (nextTime > animation->Duration) { + nextTime = animation->Duration; + } else if (nextTime < 0) { + nextTime = 0; + } + (double&)animationComponent["Speed" + std::to_string(i)] = 0.0; Events::AnimationComplete e; e.Entity = entity; e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)]; m_EventBroker->Publish(e); } else { - if (glm::abs(nextTime) > animation->Duration) { - (double&)animationComponent["Time" + std::to_string(i)] = glm::abs(nextTime) - animation->Duration; - } else { - (double&)animationComponent["Time" + std::to_string(i)] = nextTime; + if (nextTime > animation->Duration) { + nextTime -= animation->Duration; + } else if (nextTime < 0) { + nextTime += animation->Duration; } } + + (double&)animationComponent["Time" + std::to_string(i)] = nextTime; } }