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 "supertux/direction.hpp" 23 #include "video/canvas.hpp" 24 #include "video/drawing_context.hpp" 30 LOOPS_CONTINUED = -100
37 SpritePtr clone()
const;
40 void draw(
Canvas& canvas,
const Vector& pos,
int layer,
42 void draw_scaled(
Canvas& canvas,
const Rectf& dest_rect,
int layer,
46 void set_action(
const std::string& name,
int loops = -1);
51 void set_action(
const std::string& name,
const Direction& dir,
int loops = -1);
56 void set_action(
const Direction& dir,
const std::string& name,
int loops = -1);
61 void set_action(
const Direction& dir,
int loops = -1);
66 void set_frame_progress(
float frame_progress) { m_frame = frame_progress; }
68 void set_frame(
int frame) { m_frameidx = frame; }
71 void stop_animation() { m_animation_loops = 0; }
73 void pause_animation() { m_is_paused =
true; }
74 void resume_animation() { m_is_paused =
false; }
80 int get_frames()
const {
return static_cast<int>(m_action->surfaces.size()); }
89 const std::string&
get_name()
const {
return m_data.name; }
92 const std::string&
get_action()
const {
return m_action->name; }
94 int get_width()
const;
95 int get_height()
const;
97 const std::optional<std::vector<SurfacePtr>> get_action_surfaces(
const std::string& name)
const;
118 void set_color(
const Color& color);
119 Color get_color()
const;
121 void set_alpha(
float alpha);
122 float get_alpha()
const;
124 void set_blend(
const Blend& blend);
125 Blend get_blend()
const;
127 bool has_action (
const std::string& name)
const {
return (m_data.get_action(name) !=
nullptr); }
128 size_t get_actions_count()
const {
return m_data.actions.size(); }
139 int m_animation_loops;
147 const SpriteData::Action* m_action;
Definition: sprite_data.hpp:28
Definition: sprite.hpp:26
float get_current_hitbox_width() const
return width of current action's hitbox
Definition: sprite.cpp:246
void set_angle(float angle)
Set the angle of the sprite rotation in degree.
Definition: sprite.cpp:264
bool is_current_hitbox_unisolid() const
Return the "unisolid" property for the current action's hitbox.
Definition: sprite.cpp:228
void draw(Canvas &canvas, const Vector &pos, int layer, Flip flip=NO_FLIP)
Draw sprite, automatically calculates next frame.
Definition: sprite.cpp:165
const std::string & get_name() const
Get sprite's name.
Definition: sprite.hpp:89
int get_current_frame() const
Get currently drawn frame.
Definition: sprite.hpp:83
void set_action(const std::string &name, int loops=-1)
Set action (or state)
Definition: sprite.cpp:94
Rectf get_current_hitbox() const
return current action's hitbox, relative to 0,0
Definition: sprite.cpp:258
bool animation_done() const
Check if animation is stopped or not.
Definition: sprite.cpp:130
float get_current_hitbox_height() const
return height of current action's hitbox
Definition: sprite.cpp:252
void set_animation_loops(int loops=-1)
Set number of animation cycles until animation stops.
Definition: sprite.hpp:64
float get_current_hitbox_x_offset() const
return x-offset of current action's hitbox, relative to start of image
Definition: sprite.cpp:234
const std::string & get_action() const
Get current action name.
Definition: sprite.hpp:92
int get_frames() const
Get current action total frames.
Definition: sprite.hpp:80
float get_current_hitbox_y_offset() const
return y-offset of current action's hitbox, relative to start of image
Definition: sprite.cpp:240
Definition: canvas.hpp:43
float get_angle() const
Get the angle of the sprite rotation in degree.
Definition: sprite.cpp:270
float get_current_frame_progress() const
Get current frame progress.
Definition: sprite.hpp:86