animated_sprite_2d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifndef ANIMATED_SPRITE_2D_H
  31. #define ANIMATED_SPRITE_2D_H
  32. #include "scene/2d/node_2d.h"
  33. #include "scene/resources/sprite_frames.h"
  34. class AnimatedSprite2D : public Node2D {
  35. GDCLASS(AnimatedSprite2D, Node2D);
  36. Ref<SpriteFrames> frames;
  37. String autoplay;
  38. bool playing = false;
  39. StringName animation = SceneStringName(default_);
  40. int frame = 0;
  41. float speed_scale = 1.0;
  42. float custom_speed_scale = 1.0;
  43. bool centered = true;
  44. Point2 offset;
  45. real_t frame_speed_scale = 1.0;
  46. real_t frame_progress = 0.0;
  47. bool hflip = false;
  48. bool vflip = false;
  49. void _res_changed();
  50. double _get_frame_duration();
  51. void _calc_frame_speed_scale();
  52. void _stop_internal(bool p_reset);
  53. Rect2 _get_rect() const;
  54. protected:
  55. #ifndef DISABLE_DEPRECATED
  56. bool _set(const StringName &p_name, const Variant &p_value);
  57. #endif // DISABLE_DEPRECATED
  58. static void _bind_methods();
  59. void _notification(int p_what);
  60. void _validate_property(PropertyInfo &p_property) const;
  61. public:
  62. #ifdef TOOLS_ENABLED
  63. virtual Dictionary _edit_get_state() const override;
  64. virtual void _edit_set_state(const Dictionary &p_state) override;
  65. virtual void _edit_set_pivot(const Point2 &p_pivot) override;
  66. virtual Point2 _edit_get_pivot() const override;
  67. virtual bool _edit_use_pivot() const override;
  68. #endif // TOOLS_ENABLED
  69. #ifdef DEBUG_ENABLED
  70. virtual Rect2 _edit_get_rect() const override;
  71. virtual bool _edit_use_rect() const override;
  72. #endif // DEBUG_ENABLED
  73. virtual Rect2 get_anchorable_rect() const override;
  74. void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
  75. Ref<SpriteFrames> get_sprite_frames() const;
  76. void play(const StringName &p_name = StringName(), float p_custom_scale = 1.0, bool p_from_end = false);
  77. void play_backwards(const StringName &p_name = StringName());
  78. void pause();
  79. void stop();
  80. bool is_playing() const;
  81. void set_animation(const StringName &p_name);
  82. StringName get_animation() const;
  83. void set_autoplay(const String &p_name);
  84. String get_autoplay() const;
  85. void set_frame(int p_frame);
  86. int get_frame() const;
  87. void set_frame_progress(real_t p_progress);
  88. real_t get_frame_progress() const;
  89. void set_frame_and_progress(int p_frame, real_t p_progress);
  90. void set_speed_scale(float p_speed_scale);
  91. float get_speed_scale() const;
  92. float get_playing_speed() const;
  93. void set_centered(bool p_center);
  94. bool is_centered() const;
  95. void set_offset(const Point2 &p_offset);
  96. Point2 get_offset() const;
  97. void set_flip_h(bool p_flip);
  98. bool is_flipped_h() const;
  99. void set_flip_v(bool p_flip);
  100. bool is_flipped_v() const;
  101. PackedStringArray get_configuration_warnings() const override;
  102. #ifdef TOOLS_ENABLED
  103. virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
  104. #endif // TOOLS_ENABLED
  105. AnimatedSprite2D();
  106. };
  107. #endif // ANIMATED_SPRITE_2D_H