aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/animations/je_animator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/animations/je_animator.cpp')
-rw-r--r--src/libjin/graphics/animations/je_animator.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/libjin/graphics/animations/je_animator.cpp b/src/libjin/graphics/animations/je_animator.cpp
index 4528e8c..9550116 100644
--- a/src/libjin/graphics/animations/je_animator.cpp
+++ b/src/libjin/graphics/animations/je_animator.cpp
@@ -48,11 +48,12 @@ namespace JinEngine
{
if (!mIsActive || !mAnimation)
return;
+ float interval = 1 / mSpeed;
mTick += dt;
uint fc = mAnimation->getFrameCount();
- while (mTick >= mSpeed)
+ while (mTick >= interval)
{
- mTick -= mSpeed;
+ mTick -= interval;
++mIndex;
if (mLoop)
mIndex %= fc;
@@ -65,9 +66,9 @@ namespace JinEngine
mIndex = 0;
}
- void Animator::render(float x, float y, float sx, float sy, float r)
+ void Animator::render(float x, float y, float sx, float sy, float r) const
{
- if (!mIsActive || !mAnimation)
+ if (!mAnimation)
return;
const Sprite* spr = mAnimation->getFrame(mIndex);
if (spr)
@@ -80,6 +81,38 @@ namespace JinEngine
}
+ void Animator::setSpeed(float speed)
+ {
+ mSpeed = speed;
+ }
+
+ void Animator::setDefaultSpeed()
+ {
+ if(mAnimation != nullptr)
+ mSpeed = mAnimation->getSpeed();
+ else
+ {
+ jin_log_error("Animation is null.");
+ return;
+ }
+ }
+
+ void Animator::setLoop(bool loop)
+ {
+ mLoop = loop;
+ }
+
+ void Animator::setDefaultLoop()
+ {
+ if(mAnimation != nullptr)
+ mLoop = mAnimation->isLoop();
+ else
+ {
+ jin_log_error("Animation is null.");
+ return;
+ }
+ }
+
}
}
} \ No newline at end of file