Animations now pause correctly when not looping

This commit is contained in:
2015-10-22 17:01:14 +02:00
parent c7bef473d9
commit 3e10d75d75
2 changed files with 11 additions and 12 deletions
+9 -10
View File
@@ -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;
}
}
}
+2 -2
View File
@@ -69,7 +69,7 @@ std::vector<glm::mat4> 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) {