UGDK
|
00001 #ifndef HORUSEYE_FRAMEWORK_SPRITE_H_ 00002 #define HORUSEYE_FRAMEWORK_SPRITE_H_ 00003 00004 #include <ugdk/math/vector2D.h> 00005 #include <ugdk/graphic.h> 00006 #include <ugdk/graphic/drawable.h> 00007 #include <ugdk/action/animation.h> 00008 00009 namespace ugdk { 00010 namespace graphic { 00011 00012 class Sprite : public Drawable { 00013 public: 00014 Sprite(const Spritesheet *spritesheet, action::AnimationSet *set = NULL); 00015 explicit Sprite(const std::string& spritesheet_tag, action::AnimationSet *set = NULL); 00016 explicit Sprite(const std::string& spritesheet_tag, const std::string& animation_set_tag); 00017 explicit Sprite(const Spritesheet *spritesheet, const std::string& animation_set_tag); 00018 virtual ~Sprite(); 00019 00020 void Update(double dt); 00021 void Draw() const; 00022 const Vector2D& size() const; 00023 00025 00026 void SelectAnimation(const std::string& animation_name) { 00027 animation_manager_->Select(animation_name); 00028 } 00030 00031 void SelectAnimation(int animation_index) { 00032 animation_manager_->Select(animation_index); 00033 } 00034 00036 00039 void SetAnimationSpeedupFactor(double factor) { animation_manager_->set_speedup_factor(factor); } 00040 00042 00045 void SetAnimationSlowdownFactor(double factor) { animation_manager_->set_slowdown_factor(factor); } 00046 00048 00051 double GetAnimationFPS() const { return animation_manager_->fps(); } 00052 00054 00057 void AddObserverToAnimation(action::Observer *observer) { 00058 animation_manager_->AddObserver(observer); 00059 } 00060 00061 void AddTickFunctionToAnimation(std::tr1::function<void (void)> tick) { 00062 animation_manager_->AddTickFunction(tick); 00063 } 00064 00066 00068 int GetAnimationFrameNumber() const { return animation_manager_->n_frames(); } 00069 00071 00073 void SetDefaultFrame(int frame) { 00074 animation_manager_->set_default_frame(frame); 00075 } 00076 00077 00078 private: 00079 const Spritesheet *spritesheet_; 00080 action::AnimationManager *animation_manager_; 00081 00083 00085 }; 00086 00087 } // namespace graphic 00088 } // namespace ugdk 00089 00090 #endif //HORUSEYE_FRAMEWORK_SPRITE_H_