From 3e10d75d7572e5b8444f066ba24abb04ef673e8b Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Thu, 22 Oct 2015 17:01:14 +0200 Subject: [PATCH] Animations now pause correctly when not looping --- src/game/Rendering/AnimationSystem.cpp | 19 +++++++++---------- src/game/Rendering/Skeleton.cpp | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/game/Rendering/AnimationSystem.cpp b/src/game/Rendering/AnimationSystem.cpp index 8a44ebb..942c807 100644 --- a/src/game/Rendering/AnimationSystem.cpp +++ b/src/game/Rendering/AnimationSystem.cpp @@ -35,17 +35,16 @@ void dd::Systems::AnimationSystem::Update(double dt) if (animationComponent->Speed != 0.0) { double nextTime = animationComponent->Time + animationComponent->Speed * dt; - if (glm::abs(nextTime) > animation->Duration) { - if (!animationComponent->Loop) { - animationComponent->Time = glm::sign(nextTime) * animation->Duration; - animationComponent->Speed = 0.0; - LOG_DEBUG("Animation \"%s\" on Entity %i finished.", animationComponent->Name.c_str(), ent); - Events::AnimationComplete e; - e.Entity = ent; - e.Animation = animationComponent->Name; - } + if (!animationComponent->Loop && glm::abs(nextTime) > animation->Duration) { + animationComponent->Time = glm::sign(nextTime) * animation->Duration; + animationComponent->Speed = 0.0; + LOG_DEBUG("Animation \"%s\" on Entity %i finished.", animationComponent->Name.c_str(), ent); + Events::AnimationComplete e; + e.Entity = ent; + e.Animation = animationComponent->Name; + } else { + animationComponent->Time = nextTime; } - animationComponent->Time = nextTime; } } } diff --git a/src/game/Rendering/Skeleton.cpp b/src/game/Rendering/Skeleton.cpp index d68d59a..319bfd4 100644 --- a/src/game/Rendering/Skeleton.cpp +++ b/src/game/Rendering/Skeleton.cpp @@ -69,7 +69,7 @@ std::vector dd::Skeleton::GetFrameBones(const Animation& animation, d int currentKeyframeIndex = GetKeyframe(animation, time); const Animation::Keyframe& currentFrame = animation.Keyframes[currentKeyframeIndex]; - const Animation::Keyframe& nextFrame = animation.Keyframes[currentKeyframeIndex + 1]; + const Animation::Keyframe& nextFrame = animation.Keyframes[(currentKeyframeIndex + 1) % animation.Keyframes.size()]; float alpha = (time - currentFrame.Time) / (nextFrame.Time - currentFrame.Time); //auto animationFrame = Animations[""].Keyframes[frame]; @@ -149,7 +149,7 @@ int dd::Skeleton::GetKeyframe(const Animation& animation, double time) { if (time < 0) time = 0; - if (time > animation.Duration) + if (time >= animation.Duration) return animation.Keyframes.size() - 1; for (int keyframe = 0; keyframe < animation.Keyframes.size(); ++keyframe) {