diff options
Diffstat (limited to 'src/libjin/graphics/animations')
-rw-r--r-- | src/libjin/graphics/animations/animation.cpp | 94 | ||||
-rw-r--r-- | src/libjin/graphics/animations/animation.h | 62 | ||||
-rw-r--r-- | src/libjin/graphics/animations/animator.cpp | 240 | ||||
-rw-r--r-- | src/libjin/graphics/animations/animator.h | 64 |
4 files changed, 230 insertions, 230 deletions
diff --git a/src/libjin/graphics/animations/animation.cpp b/src/libjin/graphics/animations/animation.cpp index 168c3e3..3eb67c0 100644 --- a/src/libjin/graphics/animations/animation.cpp +++ b/src/libjin/graphics/animations/animation.cpp @@ -5,61 +5,61 @@ using namespace JinEngine::Math; namespace JinEngine { - namespace Graphics - { - namespace Animations - { + namespace Graphics + { + namespace Animations + { - Animation::Animation() - : mLoop(true) - { - } + Animation::Animation() + : mLoop(true) + { + } - void Animation::addFrame(const Sprite* frame) - { - if(frame != nullptr) - mFrames.push_back(frame); - } + void Animation::addFrame(const Sprite* frame) + { + if(frame != nullptr) + mFrames.push_back(frame); + } - void Animation::addFrames(const std::vector<Sprite*>& frames) - { - mFrames.insert(mFrames.end(), frames.begin(), frames.end()); - } + void Animation::addFrames(const std::vector<Sprite*>& frames) + { + mFrames.insert(mFrames.end(), frames.begin(), frames.end()); + } - void Animation::setSpeed(float speed) - { - mSpeed = speed; - } + void Animation::setSpeed(float speed) + { + mSpeed = speed; + } - void Animation::setLoop(bool loop) - { - mLoop = loop; - } + void Animation::setLoop(bool loop) + { + mLoop = loop; + } - const Sprite* Animation::getFrame(uint index) const - { - if (mFrames.size() == 0) - return nullptr; - if (without<uint>(index, 0, mFrames.size() - 1)) - return nullptr; - return mFrames[index]; - } + const Sprite* Animation::getFrame(uint index) const + { + if (mFrames.size() == 0) + return nullptr; + if (without<uint>(index, 0, mFrames.size() - 1)) + return nullptr; + return mFrames[index]; + } - uint Animation::getFrameCount() const - { - return mFrames.size(); - } + uint Animation::getFrameCount() const + { + return mFrames.size(); + } - bool Animation::isLoop() const - { - return mLoop; - } + bool Animation::isLoop() const + { + return mLoop; + } - float Animation::getSpeed() const - { - return mSpeed; - } + float Animation::getSpeed() const + { + return mSpeed; + } - } - } + } + } }
\ No newline at end of file diff --git a/src/libjin/graphics/animations/animation.h b/src/libjin/graphics/animations/animation.h index 72565fc..f48ff33 100644 --- a/src/libjin/graphics/animations/animation.h +++ b/src/libjin/graphics/animations/animation.h @@ -10,50 +10,50 @@ namespace JinEngine { - namespace Graphics - { - namespace Animations - { + namespace Graphics + { + namespace Animations + { - /// - /// Animation clip with key. - /// - class Animation : public Object - { - public: - Animation(); - - void addFrame(const Sprite* frame); + /// + /// Animation clip with key. + /// + class Animation : public Object + { + public: + Animation(); + + void addFrame(const Sprite* frame); - void addFrames(const std::vector<Sprite*>& frames); + void addFrames(const std::vector<Sprite*>& frames); - void setLoop(bool loop); + void setLoop(bool loop); - void setSpeed(float speed); + void setSpeed(float speed); - bool isLoop() const; + bool isLoop() const; - float getSpeed() const; + float getSpeed() const; - uint getFrameCount() const; + uint getFrameCount() const; - const Sprite* getFrame(uint index) const; + const Sprite* getFrame(uint index) const; - private: + private: - std::vector<const Sprite*> mFrames; + std::vector<const Sprite*> mFrames; - /// - /// Frame per second. - /// - float mSpeed; + /// + /// Frame per second. + /// + float mSpeed; - float mLoop; - - }; + float mLoop; + + }; - } // namespace Animations - } // namespace Graphics + } // namespace Animations + } // namespace Graphics } // namespace JinEngine #endif
\ No newline at end of file diff --git a/src/libjin/graphics/animations/animator.cpp b/src/libjin/graphics/animations/animator.cpp index 8db3bc2..d3fac8b 100644 --- a/src/libjin/graphics/animations/animator.cpp +++ b/src/libjin/graphics/animations/animator.cpp @@ -5,124 +5,124 @@ 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(); - } - - } - } + 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 diff --git a/src/libjin/graphics/animations/animator.h b/src/libjin/graphics/animations/animator.h index 263c7cb..6a0cb28 100644 --- a/src/libjin/graphics/animations/animator.h +++ b/src/libjin/graphics/animations/animator.h @@ -10,61 +10,61 @@ namespace JinEngine { - namespace Graphics - { - namespace Animations - { + namespace Graphics + { + namespace Animations + { - class Animator : public Object, public Renderable - { - public: - Animator(); + class Animator : public Object, public Renderable + { + public: + Animator(); - void play(); + void play(); - void pause(); + void pause(); - void resume(); + void resume(); - void update(float dt); + void update(float dt); - void rewind(); + void rewind(); - void render(float x, float y, float sx, float sy, float r) const override; + void render(float x, float y, float sx, float sy, float r) const override; - void setAnimation(const Animation* anim); + void setAnimation(const Animation* anim); - void forceToFrame(uint index); + void forceToFrame(uint index); - void setSpeed(float speed); + void setSpeed(float speed); - void setDefaultSpeed(); + void setDefaultSpeed(); - void setLoop(bool loop); + void setLoop(bool loop); - void setDefaultLoop(); + void setDefaultLoop(); - float getSpeed(); + float getSpeed(); - uint getFrameCount(); + uint getFrameCount(); - private: - const Animation* mAnimation; + private: + const Animation* mAnimation; - uint mIndex; + uint mIndex; - float mTick; + float mTick; - bool mIsActive; + bool mIsActive; - float mSpeed; + float mSpeed; - bool mLoop; + bool mLoop; - }; + }; - } - } + } + } } #endif
\ No newline at end of file |