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
27 #include "video/surface.hpp"
28 #include "math/vector.hpp"
29 #include "sprite_data.hpp"
36 Sprite(SpriteData& data);
37 Sprite(const Sprite& other);
40 /** Draw sprite, automatically calculates next frame */
41 void draw(DrawingContext& context, const Vector& pos, int layer);
43 void draw_part(DrawingContext& context, const Vector& source,
44 const Vector& size, const Vector& pos, int layer);
46 /** Set action (or state) */
47 void set_action(const std::string& act, int loops = -1);
49 /** Set number of animation cycles until animation stops */
50 void set_animation_loops(int loops = -1)
51 { animation_loops = loops; }
54 void set_fps(float new_fps);
58 { animation_loops = 0; }
59 /** Check if animation is stopped or not */
60 bool animation_done();
63 { return action->fps; }
64 /** Get current action total frames */
65 int get_frames() const
66 { return action->surfaces.size(); }
67 /** Get sprite's name */
68 const std::string& get_name() const
70 /** Get current action name */
71 const std::string& get_action() const
72 { return action->name; }
74 int get_width() const;
75 int get_height() const;
77 /** return x-offset of current action's hitbox, relative to start of image */
78 float get_current_hitbox_x_offset() const;
79 /** return y-offset of current action's hitbox, relative to start of image */
80 float get_current_hitbox_y_offset() const;
81 /** return width of current action's hitbox */
82 float get_current_hitbox_width() const;
83 /** return height of current action's hitbox */
84 float get_current_hitbox_height() const;
86 /** Get current frame */
88 { return (int)frame; }
89 /** Set current frame */
90 void set_frame(int frame)
92 this->frame = (frame % get_frames());
94 Surface* get_frame(unsigned int frame)
96 assert(frame < action->surfaces.size());
97 return action->surfaces[frame];
109 SpriteData::Action* action;