4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.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
28 #include "video/surface.h"
29 #include "math/vector.h"
30 #include "sprite_data.h"
35 Sprite(SpriteData& data);
36 Sprite(const Sprite& other);
39 /** Draw sprite, automatically calculates next frame */
40 void draw(DrawingContext& context, const Vector& pos, int layer,
41 Uint32 drawing_effect = NONE_EFFECT);
43 void draw_part(DrawingContext& context, const Vector& source,
44 const Vector& size, const Vector& pos, int layer,
45 Uint32 drawing_effect = NONE_EFFECT);
47 /** Set action (or state) */
48 void set_action(std::string act, int loops = -1);
52 { animation_loops = 0; }
53 /** Check if animation is stopped or not */
54 bool check_animation();
57 { return action->fps; }
58 /** Get current action total frames */
59 int get_frames() const
60 { return action->surfaces.size(); }
61 /** Get sprite's name */
62 const std::string& get_name() const
64 /** Get current action name */
65 const std::string& get_action_name() const
66 { return action->name; }
68 int get_width() const;
69 int get_height() const;
71 /** Get current frame */
73 { return (int)frame; }
74 /** Set current frame */
75 void set_frame(int frame_)
76 { if(frame_ > get_frames()) frame = 0; else frame = frame_; }
77 Surface* get_frame(unsigned int frame)
79 assert(frame < action->surfaces.size());
80 return action->surfaces[frame];
92 SpriteData::Action* action;