1/**************************************************************************/
2/* animated_sprite_2d.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef ANIMATED_SPRITE_2D_H
32#define ANIMATED_SPRITE_2D_H
33
34#include "scene/2d/node_2d.h"
35#include "scene/resources/sprite_frames.h"
36
37class AnimatedSprite2D : public Node2D {
38 GDCLASS(AnimatedSprite2D, Node2D);
39
40 Ref<SpriteFrames> frames;
41 String autoplay;
42
43 bool playing = false;
44 StringName animation = "default";
45 int frame = 0;
46 float speed_scale = 1.0;
47 float custom_speed_scale = 1.0;
48
49 bool centered = true;
50 Point2 offset;
51
52 real_t frame_speed_scale = 1.0;
53 real_t frame_progress = 0.0;
54
55 bool hflip = false;
56 bool vflip = false;
57
58 void _res_changed();
59
60 double _get_frame_duration();
61 void _calc_frame_speed_scale();
62 void _stop_internal(bool p_reset);
63
64 Rect2 _get_rect() const;
65
66protected:
67#ifndef DISABLE_DEPRECATED
68 bool _set(const StringName &p_name, const Variant &p_value);
69#endif
70 static void _bind_methods();
71 void _notification(int p_what);
72 void _validate_property(PropertyInfo &p_property) const;
73
74public:
75#ifdef TOOLS_ENABLED
76 virtual Dictionary _edit_get_state() const override;
77 virtual void _edit_set_state(const Dictionary &p_state) override;
78
79 virtual void _edit_set_pivot(const Point2 &p_pivot) override;
80 virtual Point2 _edit_get_pivot() const override;
81 virtual bool _edit_use_pivot() const override;
82 virtual Rect2 _edit_get_rect() const override;
83 virtual bool _edit_use_rect() const override;
84#endif
85
86 virtual Rect2 get_anchorable_rect() const override;
87
88 void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
89 Ref<SpriteFrames> get_sprite_frames() const;
90
91 void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false);
92 void play_backwards(const StringName &p_name = StringName());
93 void pause();
94 void stop();
95
96 bool is_playing() const;
97
98 void set_animation(const StringName &p_name);
99 StringName get_animation() const;
100
101 void set_autoplay(const String &p_name);
102 String get_autoplay() const;
103
104 void set_frame(int p_frame);
105 int get_frame() const;
106
107 void set_frame_progress(real_t p_progress);
108 real_t get_frame_progress() const;
109
110 void set_frame_and_progress(int p_frame, real_t p_progress);
111
112 void set_speed_scale(float p_speed_scale);
113 float get_speed_scale() const;
114 float get_playing_speed() const;
115
116 void set_centered(bool p_center);
117 bool is_centered() const;
118
119 void set_offset(const Point2 &p_offset);
120 Point2 get_offset() const;
121
122 void set_flip_h(bool p_flip);
123 bool is_flipped_h() const;
124
125 void set_flip_v(bool p_flip);
126 bool is_flipped_v() const;
127
128 PackedStringArray get_configuration_warnings() const override;
129 virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
130
131 AnimatedSprite2D();
132};
133
134#endif // ANIMATED_SPRITE_2D_H
135