| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
#include "scene/resources/sprite_frames.h" |
| 35 |
|
| 36 |
class AnimatedSprite2D : public Node2D { |
| 37 |
GDCLASS(AnimatedSprite2D, Node2D); |
| 38 |
|
| 39 |
Ref<SpriteFrames> frames; |
| 40 |
String autoplay; |
| 41 |
|
| 42 |
bool playing = false; |
| 43 |
StringName animation = SceneStringName(default_); |
| 44 |
int frame = 0; |
| 45 |
float speed_scale = 1.0; |
| 46 |
float custom_speed_scale = 1.0; |
| 47 |
|
| 48 |
bool centered = true; |
| 49 |
Point2 offset; |
| 50 |
|
| 51 |
real_t frame_speed_scale = 1.0; |
| 52 |
real_t frame_progress = 0.0; |
| 53 |
|
| 54 |
bool hflip = false; |
| 55 |
bool vflip = false; |
| 56 |
|
| 57 |
void _res_changed(); |
| 58 |
|
| 59 |
double _get_frame_duration(); |
| 60 |
void _calc_frame_speed_scale(); |
| 61 |
void _stop_internal(bool p_reset); |
| 62 |
|
| 63 |
Rect2 _get_rect() const; |
| 64 |
|
| 65 |
protected: |
| 66 |
#ifndef DISABLE_DEPRECATED |
| 67 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 68 |
#endif |
| 69 |
static void _bind_methods(); |
| 70 |
void _notification(int p_what); |
| 71 |
void _validate_property(PropertyInfo &p_property) const; |
| 72 |
|
| 73 |
public: |
| 74 |
#ifdef TOOLS_ENABLED |
| 75 |
virtual Dictionary _edit_get_state() const override; |
| 76 |
virtual void _edit_set_state(const Dictionary &p_state) override; |
| 77 |
|
| 78 |
virtual void _edit_set_pivot(const Point2 &p_pivot) override; |
| 79 |
virtual Point2 _edit_get_pivot() const override; |
| 80 |
virtual bool _edit_use_pivot() const override; |
| 81 |
#endif |
| 82 |
|
| 83 |
#ifdef DEBUG_ENABLED |
| 84 |
virtual Rect2 _edit_get_rect() const override; |
| 85 |
virtual bool _edit_use_rect() const override; |
| 86 |
#endif |
| 87 |
|
| 88 |
virtual Rect2 get_anchorable_rect() const override; |
| 89 |
|
| 90 |
void set_sprite_frames(const Ref<SpriteFrames> &p_frames); |
| 91 |
Ref<SpriteFrames> get_sprite_frames() const; |
| 92 |
|
| 93 |
void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false); |
| 94 |
void play_backwards(const StringName &p_name = StringName()); |
| 95 |
void pause(); |
| 96 |
void stop(); |
| 97 |
|
| 98 |
bool is_playing() const; |
| 99 |
|
| 100 |
void set_animation(const StringName &p_name); |
| 101 |
StringName get_animation() const; |
| 102 |
|
| 103 |
void set_autoplay(const String &p_name); |
| 104 |
String get_autoplay() const; |
| 105 |
|
| 106 |
void set_frame(int p_frame); |
| 107 |
int get_frame() const; |
| 108 |
|
| 109 |
void set_frame_progress(real_t p_progress); |
| 110 |
real_t get_frame_progress() const; |
| 111 |
|
| 112 |
void set_frame_and_progress(int p_frame, real_t p_progress); |
| 113 |
|
| 114 |
void set_speed_scale(float p_speed_scale); |
| 115 |
float get_speed_scale() const; |
| 116 |
float get_playing_speed() const; |
| 117 |
|
| 118 |
void set_centered(bool p_center); |
| 119 |
bool is_centered() const; |
| 120 |
|
| 121 |
void set_offset(const Point2 &p_offset); |
| 122 |
Point2 get_offset() const; |
| 123 |
|
| 124 |
void set_flip_h(bool p_flip); |
| 125 |
bool is_flipped_h() const; |
| 126 |
|
| 127 |
void set_flip_v(bool p_flip); |
| 128 |
bool is_flipped_v() const; |
| 129 |
|
| 130 |
PackedStringArray get_configuration_warnings() const override; |
| 131 |
|
| 132 |
#ifdef TOOLS_ENABLED |
| 133 |
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 134 |
#endif |
| 135 |
|
| 136 |
AnimatedSprite2D(); |
| 137 |
}; |