UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
animation.h
Go to the documentation of this file.
1 #ifndef UGDK_ACTION_ANIMATION_H_
2 #define UGDK_ACTION_ANIMATION_H_
3 
4 #include <vector>
5 #include <string>
6 #include <ugdk/portable/tr1.h>
7 #include FROM_TR1(functional)
8 #include <ugdk/action.h>
9 #include <ugdk/graphic.h>
10 #include <ugdk/action/animationframe.h> // FIXME: not necessary.
11 
12 
13 #define DEFAULT_PERIOD 0.1
14 
15 namespace ugdk {
16 
17 namespace action {
18 
19 class Observer;
20 class AnimationSet;
21 
22 /*TODO
23  * Represents a sprite's current animation.
24  *
25  * An AnimationManager object contains a sequence of information describing a sprite's visual behavior
26  * (animation spreadsheet frames, position, rotation, transparency, etc) throughout a corresponding sequence
27  * of the game's update frames. This per-frame information is represented by the class
28  * AnimationManager::AnimationFrame, and the sequence of this information by the AnimationManager::Animation
29  * type.
30  *
31  * Also, an AnimationManager object contains a set of all the possible animations the sprite may need.
32  * This set is represented by the AnimationSet class. Thus, a sprite needs but one AnimationManager object
33  * to access any of the animations it requires, as long as these are all properly registered
34  * in the AnimationSet object given to the AnimationManager object.
35  */
37 
38  public:
39  AnimationManager(double fps, AnimationSet *set);/*TODO: remove fps*/
41 
42  void set_slowdown_factor(const double factor) { period_scaling_factor_ = factor; }
43  //Note: try to use set_slowdown_factor() instead whenever you can.
44  void set_speedup_factor(const double factor) { set_slowdown_factor(1.0/factor); }
45 
46  //Note: try to use period() instead whenever you can.
47  double fps() const;
48  double period() const;
49  unsigned int n_frames() const;
50 
51  int GetFrame() const;
52  void set_default_frame(int default_frame) { default_frame_ = default_frame; }
54  void Select(const std::string& name);
55  void Select(int index);
56  void Update(double delta_t);
57  void AddObserver(Observer* observer);
58  void AddTickFunction(std::tr1::function<void (void)> tick);
59 
60  private:
61  double period_scaling_factor_;
62 
63  Animation *current_animation_;
64  AnimationSet *animation_set_;
65  int current_frame_;
66  int default_frame_;
67  double elapsed_time_;
68 
69  std::vector<Observer *> observers_;
70  std::vector< std::tr1::function<void (void)> > ticks_;
71  void NotifyAllObservers();
72 
73 };
74 
75 } /* namespace action */
76 
77 } /* namespace ugdk */
78 
79 #endif /* UGDK_ACTION_ANIMATION_H_ */
80 
81