4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef SUPERTUX_SPRITE_H
21 #define SUPERTUX_SPRITE_H
26 #include "math/vector.hpp"
27 #include "math/rect.hpp"
28 #include "sprite_data.hpp"
29 #include "video/color.hpp"
30 #include "video/drawing_context.hpp"
39 Sprite(SpriteData& data);
40 Sprite(const Sprite& other);
43 /** Draw sprite, automatically calculates next frame */
44 void draw(DrawingContext& context, const Vector& pos, int layer);
46 void draw_part(DrawingContext& context, const Vector& source,
47 const Vector& size, const Vector& pos, int layer);
49 /** Set action (or state) */
50 void set_action(const std::string& act, int loops = -1);
52 /** Set number of animation cycles until animation stops */
53 void set_animation_loops(int loops = -1)
54 { animation_loops = loops; }
57 void set_fps(float new_fps);
61 { animation_loops = 0; }
62 /** Check if animation is stopped or not */
63 bool animation_done();
66 { return action->fps; }
67 /** Get current action total frames */
68 int get_frames() const
69 { return action->surfaces.size(); }
70 /** Get sprite's name */
71 const std::string& get_name() const
73 /** Get current action name */
74 const std::string& get_action() const
75 { return action->name; }
77 int get_width() const;
78 int get_height() const;
80 /** return x-offset of current action's hitbox, relative to start of image */
81 float get_current_hitbox_x_offset() const;
82 /** return y-offset of current action's hitbox, relative to start of image */
83 float get_current_hitbox_y_offset() const;
84 /** return width of current action's hitbox */
85 float get_current_hitbox_width() const;
86 /** return height of current action's hitbox */
87 float get_current_hitbox_height() const;
88 /** return current action's hitbox, relative to 0,0 */
89 Rect get_current_hitbox() const;
91 /** Set the angle of the sprite rotation in degree */
92 void set_angle(float angle);
94 /** Get the angle of the sprite rotation in degree */
95 float get_angle() const;
97 void set_color(const Color& color);
99 Color get_color() const;
101 void set_blend(const Blend& blend);
103 Blend get_blend() const;
105 /** Get current frame */
106 int get_frame() const
107 { return (int)frame; }
108 /** Set current frame */
109 void set_frame(int frame)
111 this->frame = (float) (frame % get_frames());
113 Surface* get_frame(unsigned int frame)
115 assert(frame < action->surfaces.size());
116 return action->surfaces[frame];
131 SpriteData::Action* action;