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 "sprite/sprite_ptr.hpp"
22 #include "video/drawing_context.hpp"
31 Sprite(SpriteData& data);
34 SpritePtr clone() const;
36 /** Draw sprite, automatically calculates next frame */
37 void draw(DrawingContext& context, const Vector& pos, int layer);
39 void draw_part(DrawingContext& context, const Vector& source,
40 const Vector& size, const Vector& pos, int layer);
42 /** Set action (or state) */
43 void set_action(const std::string& name, int loops = -1);
45 /** Set action (or state), but keep current frame number, loop counter, etc. */
46 void set_action_continued(const std::string& name);
48 /** Set number of animation cycles until animation stops */
49 void set_animation_loops(int loops = -1)
50 { animation_loops = loops; }
54 { animation_loops = 0; }
55 /** Check if animation is stopped or not */
56 bool animation_done();
59 { return action->fps; }
60 /** Get current action total frames */
61 int get_frames() const
62 { return action->surfaces.size(); }
63 /** Get sprite's name */
64 const std::string& get_name() const
66 /** Get current action name */
67 const std::string& get_action() const
68 { return action->name; }
70 int get_width() const;
71 int get_height() const;
73 /** return x-offset of current action's hitbox, relative to start of image */
74 float get_current_hitbox_x_offset() const;
75 /** return y-offset of current action's hitbox, relative to start of image */
76 float get_current_hitbox_y_offset() const;
77 /** return width of current action's hitbox */
78 float get_current_hitbox_width() const;
79 /** return height of current action's hitbox */
80 float get_current_hitbox_height() const;
81 /** return current action's hitbox, relative to 0,0 */
82 Rectf get_current_hitbox() const;
84 /** Set the angle of the sprite rotation in degree */
85 void set_angle(float angle);
87 /** Get the angle of the sprite rotation in degree */
88 float get_angle() const;
90 void set_color(const Color& color);
92 Color get_color() const;
94 void set_blend(const Blend& blend);
96 Blend get_blend() const;
98 /** Get current frame */
100 { return (int)frame; }
101 /** Set current frame */
102 void set_frame(int frame_)
104 this->frame = (float) (frame_ % get_frames());
106 SurfacePtr get_frame(unsigned int frame_)
108 assert(frame_ < action->surfaces.size());
109 return action->surfaces[frame_];
124 const SpriteData::Action* action;
127 Sprite(const Sprite& other);
128 Sprite& operator=(const Sprite&);