Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Added SingleShot mode to the StopMotionAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriiKoniushenko committed Oct 14, 2023
1 parent 013af90 commit 4ca1a74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion game/source/VaKon2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void VaKon2D::start()
StopMotionAnimation animation;
animation.setupAnimation({{0, 0}, {32, 32}}, {{544, 0}, {32, 32}}, widget);
animation.setFrameGap(100);
animation.setMode(IAnimation::Mode::PingPong);
animation.setMode(IAnimation::Mode::Repeating);
animation.start();

while (!GetWindow().shouldClose())
Expand Down
29 changes: 26 additions & 3 deletions lib/core/animations/source/StopMotionAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void StopMotionAnimation::draw(ShaderPack& shaderPack)
{
case Mode::PingPong:
{
const auto cooldown = (std::chrono::system_clock::now() - lastAnimatingFrame).count() / 10000ll;
const auto cooldown = (std::chrono::system_clock::now() - lastAnimatingFrame).count() / 10'000ll;
if (cooldown >= frameGap_)
{
if (direction_ == PingPongDirection::ToEnd)
Expand Down Expand Up @@ -147,10 +147,10 @@ void StopMotionAnimation::draw(ShaderPack& shaderPack)
}
case Mode::Repeating:
{
const auto cooldown = (std::chrono::system_clock::now() - lastAnimatingFrame).count() / 1000ll;
const auto cooldown = (std::chrono::system_clock::now() - lastAnimatingFrame).count() / 10'000ll;
if (cooldown >= frameGap_)
{
if (currentFrame_ >= framesCount_)
if (currentFrame_ >= framesCount_ - 1)
{
currentOffsetPosition_ = startPosition_;
currentFrame_ = 0;
Expand All @@ -166,6 +166,29 @@ void StopMotionAnimation::draw(ShaderPack& shaderPack)
}
break;
}
case Mode::SingleShot:
{
const auto cooldown = (std::chrono::system_clock::now() - lastAnimatingFrame).count() / 10'000ll;
if (cooldown >= frameGap_)
{
if (currentFrame_ >= framesCount_ - 1)
{
currentOffsetPosition_ = endPosition_;
widget_->setTextureRect(Utils::IRect{currentOffsetPosition_, textureSize_});
currentFrame_ = framesCount_;
break;
}

currentOffsetPosition_ += offsetPosition_;

++currentFrame_;

widget_->setTextureRect(Utils::IRect{currentOffsetPosition_, textureSize_});

lastAnimatingFrame = std::chrono::system_clock::now();
}
break;
}
}
}
widget_->draw(shaderPack);
Expand Down

0 comments on commit 4ca1a74

Please sign in to comment.