X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsprite%2Fsprite.hpp;h=2c36b0df431ee0604602cf11abf29fa0498d5703;hb=6492679a300bff2c17505c5d9bc9d333eeba384d;hp=6e90a8471fb544d5eb0f5aed187ab7d03c918d23;hpb=12a28b64dcce9c7ff706451b4f3aecd201cc8a5f;p=supertux.git diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index 6e90a8471..2c36b0df4 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -18,6 +18,7 @@ #define HEADER_SUPERTUX_SPRITE_SPRITE_HPP #include "sprite/sprite_data.hpp" +#include "sprite/sprite_ptr.hpp" #include "video/drawing_context.hpp" class Surface; @@ -28,11 +29,13 @@ class Sprite { public: Sprite(SpriteData& data); - Sprite(const Sprite& other); ~Sprite(); + SpritePtr clone() const; + /** Draw sprite, automatically calculates next frame */ - void draw(DrawingContext& context, const Vector& pos, int layer); + void draw(DrawingContext& context, const Vector& pos, int layer, + DrawingEffect effect = NO_EFFECT); void draw_part(DrawingContext& context, const Vector& source, const Vector& size, const Vector& pos, int layer); @@ -47,9 +50,6 @@ public: void set_animation_loops(int loops = -1) { animation_loops = loops; } - /** Set framerate */ - void set_fps(float new_fps); - /* Stop animation */ void stop_animation() { animation_loops = 0; } @@ -59,7 +59,7 @@ public: float get_fps() const { return action->fps; } /** Get current action total frames */ - int get_frames() const + unsigned int get_frames() const { return action->surfaces.size(); } /** Get sprite's name */ const std::string& get_name() const @@ -80,7 +80,7 @@ public: /** return height of current action's hitbox */ float get_current_hitbox_height() const; /** return current action's hitbox, relative to 0,0 */ - Rect get_current_hitbox() const; + Rectf get_current_hitbox() const; /** Set the angle of the sprite rotation in degree */ void set_angle(float angle); @@ -97,34 +97,44 @@ public: Blend get_blend() const; /** Get current frame */ - int get_frame() const - { return (int)frame; } + unsigned int get_frame() const + { return frameidx; } /** Set current frame */ void set_frame(int frame_) { - this->frame = (float) (frame_ % get_frames()); + this->frame = 0; + this->frameidx = frame_ % get_frames(); } - Surface* get_frame(unsigned int frame_) + SurfacePtr get_frame(unsigned int frame_) { assert(frame_ < action->surfaces.size()); return action->surfaces[frame_]; } + bool has_action (const std::string& name) + { + return (data.get_action(name) != NULL); + } + private: void update(); SpriteData& data; + // between 0 and 1 float frame; + // between 0 and get_frames() + unsigned int frameidx; int animation_loops; float last_ticks; float angle; Color color; Blend blend; - SpriteData::Action* action; + const SpriteData::Action* action; private: + Sprite(const Sprite& other); Sprite& operator=(const Sprite&); };