2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_SPRITE_SPRITE_HPP
18 #define HEADER_SUPERTUX_SPRITE_SPRITE_HPP
20 #include "sprite/sprite_data.hpp"
21 #include "video/drawing_context.hpp"
30 Sprite(SpriteData& data);
31 Sprite(const Sprite& other);
34 /** Draw sprite, automatically calculates next frame */
35 void draw(DrawingContext& context, const Vector& pos, int layer);
37 void draw_part(DrawingContext& context, const Vector& source,
38 const Vector& size, const Vector& pos, int layer);
40 /** Set action (or state) */
41 void set_action(const std::string& name, int loops = -1);
43 /** Set action (or state), but keep current frame number, loop counter, etc. */
44 void set_action_continued(const std::string& name);
46 /** Set number of animation cycles until animation stops */
47 void set_animation_loops(int loops = -1)
48 { animation_loops = loops; }
51 void set_fps(float new_fps);
55 { animation_loops = 0; }
56 /** Check if animation is stopped or not */
57 bool animation_done();
60 { return action->fps; }
61 /** Get current action total frames */
62 int get_frames() const
63 { return action->surfaces.size(); }
64 /** Get sprite's name */
65 const std::string& get_name() const
67 /** Get current action name */
68 const std::string& get_action() const
69 { return action->name; }
71 int get_width() const;
72 int get_height() const;
74 /** return x-offset of current action's hitbox, relative to start of image */
75 float get_current_hitbox_x_offset() const;
76 /** return y-offset of current action's hitbox, relative to start of image */
77 float get_current_hitbox_y_offset() const;
78 /** return width of current action's hitbox */
79 float get_current_hitbox_width() const;
80 /** return height of current action's hitbox */
81 float get_current_hitbox_height() const;
82 /** return current action's hitbox, relative to 0,0 */
83 Rect get_current_hitbox() const;
85 /** Set the angle of the sprite rotation in degree */
86 void set_angle(float angle);
88 /** Get the angle of the sprite rotation in degree */
89 float get_angle() const;
91 void set_color(const Color& color);
93 Color get_color() const;
95 void set_blend(const Blend& blend);
97 Blend get_blend() const;
99 /** Get current frame */
100 int get_frame() const
101 { return (int)frame; }
102 /** Set current frame */
103 void set_frame(int frame_)
105 this->frame = (float) (frame_ % get_frames());
107 Surface* get_frame(unsigned int frame_)
109 assert(frame_ < action->surfaces.size());
110 return action->surfaces[frame_];
125 SpriteData::Action* action;
128 Sprite& operator=(const Sprite&);