Animations now pause correctly when not looping
This commit is contained in:
@@ -35,19 +35,18 @@ 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool dd::Systems::AnimationSystem::OnPause(const Events::Pause& e)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user