aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/animations/animation.cpp
blob: 3eb67c0f0a4138e854c09751b1168de323f9b1cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "../../math/vector2.hpp"
#include "animation.h"

using namespace JinEngine::Math;

namespace JinEngine
{
	namespace Graphics
	{
		namespace Animations
		{

			Animation::Animation()
				: mLoop(true)
			{
			}

			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::setSpeed(float speed)
			{
				mSpeed = speed;
			}

			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];
			}

			uint Animation::getFrameCount() const
			{
				return mFrames.size();
			}

			bool Animation::isLoop() const
			{
				return mLoop;
			}

			float Animation::getSpeed() const
			{
				return mSpeed;
			}

		}
	}
}