diff options
| author | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 | 
|---|---|---|
| committer | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 | 
| commit | 160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch) | |
| tree | abe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/graphics/animations/animator.cpp | |
| parent | e095043485d1d298571af6d9eca7f0db9009ea7a (diff) | |
Diffstat (limited to 'src/libjin/graphics/animations/animator.cpp')
| -rw-r--r-- | src/libjin/graphics/animations/animator.cpp | 240 | 
1 files changed, 120 insertions, 120 deletions
| 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 | 
