Dragonfly 4.22
A text-based game engine
Animation.h
1///
2/// An animation for a sprite
3///
4
5#ifndef __ANIMATION_H__
6#define __ANIMATION_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Box.h"
13#include "Sprite.h"
14
15namespace df {
16
17class Animation {
18
19 private:
20 Sprite *m_p_sprite; ///< Sprite associated with Animation.
21 int m_index; ///< Current index frame for Sprite.
22 int m_slowdown_count; ///< Slowdown counter (-1 means stop).
23 std::string m_name; ///< Sprite name in ResourceManager.
24 Transform m_transform; ///< Transform sprite before drawing.
25 bool m_modified; ///< True if modified since serialize().
26
27 public:
28 /// Animation constructor
30
31 /// Set associated Sprite to new one.
32 /// Note, Sprite is managed by ResourceManager.
33 /// Set Sprite index to 0 (first frame).
34 void setSprite(Sprite *p_new_sprite);
35
36 /// Return pointer to associated Sprite.
37 const Sprite *getSprite() const;
38
39 /// Set Sprite name (in ResourceManager).
40 void setName(std::string new_name);
41
42 /// Get Sprite name (in ResourceManager).
43 std::string getName() const;
44
45 /// Set transform for Sprite.
46 void setTransform(Transform new_transform);
47
48 /// Get transform for Sprite.
50
51 /// Set index of current Sprite frame to be displayed.
52 void setIndex(int new_index);
53
54 /// Get index of current Sprite frame to be displayed.
55 int getIndex() const;
56
57 /// Set animation slowdown count (-1 means stop animation).
58 void setSlowdownCount(int new_slowdown_count);
59
60 /// Set animation slowdown count (-1 means stop animation).
61 int getSlowdownCount() const;
62
63 /// Get bounding box of associated Sprite.
64 Box getBox() const;
65
66 /// Serialize attributes to stream.
67 /// Return 0 if ok, else -1.
68 int serialize(std::stringstream *p_ss) const;
69
70 /// Deserialize attributes from stream.
71 /// Return 0 if ok, else -1.
72 int deserialize(std::stringstream *p_ss);
73
74 /// Return true if any attributes modified since last serialize.
75 bool isModified() const;
76
77 /// Draw single frame centered at position (x,y).
78 /// Drawing accounts for slowdown, and advances Sprite frame.
79 /// Return 0 if ok, else -1.
80 int draw(Vector position);
81
82 /// Compare two Animations.
83 bool operator==(const Animation &a);
84 bool operator!=(const Animation &a);
85
86 /// Return attributes as string.
87 std::string toString() const;
88};
89
90} // end of namespace df
91#endif // __ANIMATION_H__
Definition: Animation.h:17
void setTransform(Transform new_transform)
Set transform for Sprite.
Animation()
Animation constructor.
void setSlowdownCount(int new_slowdown_count)
Set animation slowdown count (-1 means stop animation).
int m_index
Current index frame for Sprite.
Definition: Animation.h:21
std::string toString() const
Return attributes as string.
Box getBox() const
Get bounding box of associated Sprite.
int getIndex() const
Get index of current Sprite frame to be displayed.
void setIndex(int new_index)
Set index of current Sprite frame to be displayed.
Sprite * m_p_sprite
Sprite associated with Animation.
Definition: Animation.h:20
int draw(Vector position)
Draw single frame centered at position (x,y).
int serialize(std::stringstream *p_ss) const
Serialize attributes to stream.
void setSprite(Sprite *p_new_sprite)
Set associated Sprite to new one.
int getSlowdownCount() const
Set animation slowdown count (-1 means stop animation).
const Sprite * getSprite() const
Return pointer to associated Sprite.
void setName(std::string new_name)
Set Sprite name (in ResourceManager).
std::string getName() const
Get Sprite name (in ResourceManager).
int m_slowdown_count
Slowdown counter (-1 means stop).
Definition: Animation.h:22
Transform getTransform(void) const
Get transform for Sprite.
Transform m_transform
Transform sprite before drawing.
Definition: Animation.h:24
int deserialize(std::stringstream *p_ss)
Deserialize attributes from stream.
bool isModified() const
Return true if any attributes modified since last serialize.
bool operator==(const Animation &a)
Compare two Animations.
bool m_modified
True if modified since serialize().
Definition: Animation.h:25
std::string m_name
Sprite name in ResourceManager.
Definition: Animation.h:23
Definition: Box.h:16
Definition: Sprite.h:17
Definition: Vector.h:12
An animation for a sprite.
Definition: Animation.h:15
Transform
Options to transform frame before drawing.
Definition: Frame.h:18