UGDK
src/ugdk/action/animationframe.h
Go to the documentation of this file.
00001 #ifndef UGDK_ACTION_ANIMATIONFRAME_H_
00002 #define UGDK_ACTION_ANIMATIONFRAME_H_
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <ugdk/graphic/modifier.h>
00007 
00008 #define DEFAULT_PERIOD 0.1
00009 
00010 namespace ugdk {
00011 
00012 namespace action {
00013 
00014 class Observer;
00015 class AnimationSet;
00016 
00017 /*
00018  * Represents the visual behavior information of a sprite in a single game frame.
00019  */
00020 class AnimationFrame {
00021   /*
00022    * frame_: the index of the spritesheet frame that should be rendered.
00023    * modifier_: a pointer to the Modifier object describing the visual modifiers that
00024    *            should be applied to the rendered sprite.
00025    */
00026   public:
00027     AnimationFrame(int frame, graphic::Modifier *modifier = NULL)
00028         : frame_(frame), modifier_(modifier) {}
00029 
00030     int frame() const { return frame_; }
00031     graphic::Modifier *modifier() const { return modifier_; }
00032 
00033     void set_frame(const int frame) { frame_ = frame; }
00034   private:
00035     int frame_;
00036     graphic::Modifier *modifier_;
00037 };
00038 
00039 /*
00040  * Is a complex of a vector with a sequence of frame indexes, and a fixed period/fps.
00041  */
00042 class Animation : public std::vector<AnimationFrame*> {
00043   /*
00044    * period_: the inverse of the animation's fps.
00045    */
00046   public:
00047     Animation() : std::vector<AnimationFrame*>(), period_(DEFAULT_PERIOD) {}
00048 
00049     /* try to use period() instead whenever you can */
00050     double fps() const { return 1.0/period_; }
00051     double period() const { return period_; }
00052 
00053     /* try to use set_period() instead whenever you can */
00054     void set_fps(const double fps) { period_ = 1.0/fps; }
00055     void set_period(const double period) { period_ = period; }
00056 
00057   private:
00058     double period_;
00059 
00060 };
00061 
00062 } /* namespace action */
00063 
00064 } /* namespace ugdk */
00065 
00066 #endif /* UGDK_ACTION_ANIMATIONFRAME_H_ */
00067 
00068 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines