File: AnimatedSprite.h

package info (click to toggle)
jazz2-native 3.5.0-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 16,912 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (97 lines) | stat: -rw-r--r-- 3,304 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once

#include "Sprite.h"
#include "RectAnimation.h"

#include <Containers/SmallVector.h>

using namespace Death::Containers;

namespace nCine
{
	/// Animated sprite
	class AnimatedSprite : public Sprite
	{
	public:
		/// Default constructor for an animated sprite with no parent and no texture, positioned in the origin
		AnimatedSprite();
		/// Constructor for an animated sprite with a parent and texture, positioned in the relative origin
		AnimatedSprite(SceneNode* parent, Texture* texture);
		/// Constructor for an animated sprite with a texture but no parent, positioned in the origin
		explicit AnimatedSprite(Texture* texture);
		/// Constructor for an animated sprite with a parent, a texture and a specified relative position
		AnimatedSprite(SceneNode* parent, Texture* texture, float xx, float yy);
		/// Constructor for an animated sprite with a parent, a texture and a specified relative position as a vector
		AnimatedSprite(SceneNode* parent, Texture* texture, Vector2f position);
		/// Constructor for an animated sprite with a texture and a specified position but no parent
		AnimatedSprite(Texture* texture, float xx, float yy);
		/// Constructor for an animated sprite with a texture and a specified position as a vector but no parent
		AnimatedSprite(Texture* texture, Vector2f position);

		AnimatedSprite& operator=(const AnimatedSprite&) = delete;
		AnimatedSprite(AnimatedSprite&&) = default;
		AnimatedSprite& operator=(AnimatedSprite&&) = default;

		/// Returns a copy of this object
		inline AnimatedSprite clone() const {
			return AnimatedSprite(*this);
		}

		/// Returns true if the current animation is paused
		bool isPaused() const;
		/// Sets the pause state for the animation
		void setPaused(bool isPaused);

		void OnUpdate(float timeMult) override;

		/// Adds a new animation
		void addAnimation(const RectAnimation& anim);
		/// Adds a new animation with move semantics
		void addAnimation(RectAnimation&& anim);
		/// Deletes all animations
		void clearAnimations();

		/// Returns the number of animations
		inline std::uint32_t numAnimations() {
			return std::uint32_t(anims_.size());
		}
		/// Returns the array of all animations
		inline SmallVectorImpl<RectAnimation>& animations() {
			return anims_;
		}
		/// Returns the constant array of all animations
		inline const SmallVectorImpl<RectAnimation>& animations() const {
			return anims_;
		}

		/// Returns the index of the current animation
		std::uint32_t animationIndex() const {
			return currentAnimIndex_;
		}
		/// Sets current animation index and its frame number
		void setAnimationIndex(std::uint32_t animIndex);

		/// Returns the current animation, if any
		RectAnimation* currentAnimation();
		/// Returns the constant version of current animation, if any
		const RectAnimation* currentAnimation() const;

		/// Returns the frame number of current animation
		std::uint32_t frame() const;
		/// Sets current animation to a specified frame number
		void setFrame(std::uint32_t frameNum);

		inline static ObjectType sType() {
			return ObjectType::AnimatedSprite;
		}

	protected:
		/// Protected copy constructor used to clone objects
		AnimatedSprite(const AnimatedSprite& other);

	private:
		SmallVector<RectAnimation, 0> anims_;
		std::uint32_t currentAnimIndex_;
	};

}