aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/animations/je_animator.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-01-12 21:48:33 +0800
committerchai <chaifix@163.com>2019-01-12 21:48:33 +0800
commit8b00d67febf133e89f6a0bfabc41feed555dc4a9 (patch)
treefe48ef17c250afa40c2588300fcdb5920dba6951 /src/libjin/graphics/animations/je_animator.cpp
parenta907c39756ef6b368d06643afa491c49a9044a8e (diff)
*去掉文件前缀je_
Diffstat (limited to 'src/libjin/graphics/animations/je_animator.cpp')
-rw-r--r--src/libjin/graphics/animations/je_animator.cpp128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/libjin/graphics/animations/je_animator.cpp b/src/libjin/graphics/animations/je_animator.cpp
deleted file mode 100644
index 1e25639..0000000
--- a/src/libjin/graphics/animations/je_animator.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-#include "../../math/je_vector2.hpp"
-#include "je_animator.h"
-
-using namespace JinEngine::Math;
-
-namespace JinEngine
-{
- namespace Graphics
- {
- namespace Animations
- {
-
- Animator::Animator()
- : mIndex(0)
- , mTick(0)
- , mIsActive(true)
- {
- }
-
- void Animator::setAnimation(const Animation* anim)
- {
- mAnimation = anim;
- if (mAnimation)
- {
- mSpeed = mAnimation->getSpeed();
- mLoop = mAnimation->isLoop();
- }
- }
-
- void Animator::play()
- {
- mIndex = 0;
- mIsActive = true;
- mTick = 0;
- }
-
- void Animator::pause()
- {
- mIsActive = false;
- }
-
- void Animator::resume()
- {
- mIsActive = true;
- }
-
- void Animator::update(float dt)
- {
- if (!mIsActive || !mAnimation)
- return;
- float interval = 1 / mSpeed;
- mTick += dt;
- uint fc = mAnimation->getFrameCount();
- if (mTick >= interval)
- {
- mIndex += int(mTick / interval);
- mTick = fmod(mTick, interval);
- if (mLoop)
- mIndex %= fc;
- mIndex = clamp<uint>(mIndex, 0, fc - 1);
- }
- }
-
- void Animator::rewind()
- {
- mIndex = 0;
- }
-
- void Animator::render(float x, float y, float sx, float sy, float r) const
- {
- if (!mAnimation)
- return;
- const Sprite* spr = mAnimation->getFrame(mIndex);
- if (spr)
- spr->render(x, y, sx, sy, r);
- }
-
- void Animator::forceToFrame(uint index)
- {
- mIndex = index;
-
- }
-
- 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;
- }
- }
-
- float Animator::getSpeed()
- {
- return mSpeed;
- }
-
- uint Animator::getFrameCount()
- {
- return mAnimation->getFrameCount();
- }
-
- }
- }
-} \ No newline at end of file