UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
animationframe.h
Go to the documentation of this file.
1 #ifndef UGDK_ACTION_ANIMATIONFRAME_H_
2 #define UGDK_ACTION_ANIMATIONFRAME_H_
3 
4 #include <vector>
5 #include <string>
7 
8 #define DEFAULT_PERIOD 0.1
9 
10 namespace ugdk {
11 
12 namespace action {
13 
14 class Observer;
15 class AnimationSet;
16 
17 /*
18  * Represents the visual behavior information of a sprite in a single game frame.
19  */
21  /*
22  * frame_: the index of the spritesheet frame that should be rendered.
23  * modifier_: a pointer to the Modifier object describing the visual modifiers that
24  * should be applied to the rendered sprite.
25  */
26  public:
28  : frame_(frame), modifier_(modifier) {}
29 
30  int frame() const { return frame_; }
31  graphic::Modifier *modifier() const { return modifier_; }
32 
33  void set_frame(const int frame) { frame_ = frame; }
34  private:
35  int frame_;
36  graphic::Modifier *modifier_;
37 };
38 
39 /*
40  * Is a complex of a vector with a sequence of frame indexes, and a fixed period/fps.
41  */
42 class Animation : public std::vector<AnimationFrame*> {
43  /*
44  * period_: the inverse of the animation's fps.
45  */
46  public:
47  Animation() : std::vector<AnimationFrame*>(), period_(DEFAULT_PERIOD) {}
48 
49  /* try to use period() instead whenever you can */
50  double fps() const { return 1.0/period_; }
51  double period() const { return period_; }
52 
53  /* try to use set_period() instead whenever you can */
54  void set_fps(const double fps) { period_ = 1.0/fps; }
55  void set_period(const double period) { period_ = period; }
56 
57  private:
58  double period_;
59 
60 };
61 
62 } /* namespace action */
63 
64 } /* namespace ugdk */
65 
66 #endif /* UGDK_ACTION_ANIMATIONFRAME_H_ */
67 
68