From 07022c42a925d4d0c23ab31f0e75883766ce773a Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 21 Nov 2018 21:12:42 +0800 Subject: =?UTF-8?q?*=E5=8A=A8=E7=94=BB=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/graphics/animations/je_animator.cpp | 41 +++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'src/libjin/graphics/animations/je_animator.cpp') 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 -- cgit v1.1-26-g67d0