animated_sprite_2d.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /**************************************************************************/
  2. /* animated_sprite_2d.cpp */
  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. #include "animated_sprite_2d.h"
  31. #include "scene/main/viewport.h"
  32. #ifdef TOOLS_ENABLED
  33. Dictionary AnimatedSprite2D::_edit_get_state() const {
  34. Dictionary state = Node2D::_edit_get_state();
  35. state["offset"] = offset;
  36. return state;
  37. }
  38. void AnimatedSprite2D::_edit_set_state(const Dictionary &p_state) {
  39. Node2D::_edit_set_state(p_state);
  40. set_offset(p_state["offset"]);
  41. }
  42. void AnimatedSprite2D::_edit_set_pivot(const Point2 &p_pivot) {
  43. set_offset(get_offset() - p_pivot);
  44. set_position(get_transform().xform(p_pivot));
  45. }
  46. Point2 AnimatedSprite2D::_edit_get_pivot() const {
  47. return Vector2();
  48. }
  49. bool AnimatedSprite2D::_edit_use_pivot() const {
  50. return true;
  51. }
  52. #endif // TOOLS_ENABLED
  53. #ifdef DEBUG_ENABLED
  54. Rect2 AnimatedSprite2D::_edit_get_rect() const {
  55. return _get_rect();
  56. }
  57. bool AnimatedSprite2D::_edit_use_rect() const {
  58. if (frames.is_null() || !frames->has_animation(animation)) {
  59. return false;
  60. }
  61. if (frame < 0 || frame >= frames->get_frame_count(animation)) {
  62. return false;
  63. }
  64. Ref<Texture2D> t;
  65. if (animation) {
  66. t = frames->get_frame_texture(animation, frame);
  67. }
  68. return t.is_valid();
  69. }
  70. #endif // DEBUG_ENABLED
  71. Rect2 AnimatedSprite2D::get_anchorable_rect() const {
  72. return _get_rect();
  73. }
  74. Rect2 AnimatedSprite2D::_get_rect() const {
  75. if (frames.is_null() || !frames->has_animation(animation)) {
  76. return Rect2();
  77. }
  78. if (frame < 0 || frame >= frames->get_frame_count(animation)) {
  79. return Rect2();
  80. }
  81. Ref<Texture2D> t;
  82. if (animation) {
  83. t = frames->get_frame_texture(animation, frame);
  84. }
  85. if (t.is_null()) {
  86. return Rect2();
  87. }
  88. Size2 s = t->get_size();
  89. Point2 ofs = offset;
  90. if (centered) {
  91. ofs -= s / 2;
  92. }
  93. if (s == Size2(0, 0)) {
  94. s = Size2(1, 1);
  95. }
  96. return Rect2(ofs, s);
  97. }
  98. void AnimatedSprite2D::_validate_property(PropertyInfo &p_property) const {
  99. if (!frames.is_valid()) {
  100. return;
  101. }
  102. if (p_property.name == "animation") {
  103. List<StringName> names;
  104. frames->get_animation_list(&names);
  105. names.sort_custom<StringName::AlphCompare>();
  106. bool current_found = false;
  107. bool is_first_element = true;
  108. for (const StringName &E : names) {
  109. if (!is_first_element) {
  110. p_property.hint_string += ",";
  111. } else {
  112. is_first_element = false;
  113. }
  114. p_property.hint_string += String(E);
  115. if (animation == E) {
  116. current_found = true;
  117. }
  118. }
  119. if (!current_found) {
  120. if (p_property.hint_string.is_empty()) {
  121. p_property.hint_string = String(animation);
  122. } else {
  123. p_property.hint_string = String(animation) + "," + p_property.hint_string;
  124. }
  125. }
  126. return;
  127. }
  128. if (p_property.name == "frame") {
  129. if (playing) {
  130. p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY;
  131. return;
  132. }
  133. p_property.hint = PROPERTY_HINT_RANGE;
  134. if (frames->has_animation(animation) && frames->get_frame_count(animation) > 0) {
  135. p_property.hint_string = "0," + itos(frames->get_frame_count(animation) - 1) + ",1";
  136. } else {
  137. // Avoid an error, `hint_string` is required for `PROPERTY_HINT_RANGE`.
  138. p_property.hint_string = "0,0,1";
  139. }
  140. p_property.usage |= PROPERTY_USAGE_KEYING_INCREMENTS;
  141. }
  142. }
  143. void AnimatedSprite2D::_notification(int p_what) {
  144. switch (p_what) {
  145. case NOTIFICATION_READY: {
  146. if (!Engine::get_singleton()->is_editor_hint() && !frames.is_null() && frames->has_animation(autoplay)) {
  147. play(autoplay);
  148. }
  149. } break;
  150. case NOTIFICATION_INTERNAL_PROCESS: {
  151. if (frames.is_null() || !frames->has_animation(animation)) {
  152. return;
  153. }
  154. double remaining = get_process_delta_time();
  155. int i = 0;
  156. while (remaining) {
  157. // Animation speed may be changed by animation_finished or frame_changed signals.
  158. double speed = frames->get_animation_speed(animation) * speed_scale * custom_speed_scale * frame_speed_scale;
  159. double abs_speed = Math::abs(speed);
  160. if (speed == 0) {
  161. return; // Do nothing.
  162. }
  163. // Frame count may be changed by animation_finished or frame_changed signals.
  164. int fc = frames->get_frame_count(animation);
  165. int last_frame = fc - 1;
  166. if (!signbit(speed)) {
  167. // Forwards.
  168. if (frame_progress >= 1.0) {
  169. if (frame >= last_frame) {
  170. if (frames->get_animation_loop(animation)) {
  171. frame = 0;
  172. emit_signal("animation_looped");
  173. } else {
  174. frame = last_frame;
  175. pause();
  176. emit_signal(SceneStringName(animation_finished));
  177. return;
  178. }
  179. } else {
  180. frame++;
  181. }
  182. _calc_frame_speed_scale();
  183. frame_progress = 0.0;
  184. queue_redraw();
  185. emit_signal(SceneStringName(frame_changed));
  186. }
  187. double to_process = MIN((1.0 - frame_progress) / abs_speed, remaining);
  188. frame_progress += to_process * abs_speed;
  189. remaining -= to_process;
  190. } else {
  191. // Backwards.
  192. if (frame_progress <= 0) {
  193. if (frame <= 0) {
  194. if (frames->get_animation_loop(animation)) {
  195. frame = last_frame;
  196. emit_signal("animation_looped");
  197. } else {
  198. frame = 0;
  199. pause();
  200. emit_signal(SceneStringName(animation_finished));
  201. return;
  202. }
  203. } else {
  204. frame--;
  205. }
  206. _calc_frame_speed_scale();
  207. frame_progress = 1.0;
  208. queue_redraw();
  209. emit_signal(SceneStringName(frame_changed));
  210. }
  211. double to_process = MIN(frame_progress / abs_speed, remaining);
  212. frame_progress -= to_process * abs_speed;
  213. remaining -= to_process;
  214. }
  215. i++;
  216. if (i > fc) {
  217. return; // Prevents freezing if to_process is each time much less than remaining.
  218. }
  219. }
  220. } break;
  221. case NOTIFICATION_DRAW: {
  222. if (frames.is_null() || !frames->has_animation(animation)) {
  223. return;
  224. }
  225. Ref<Texture2D> texture = frames->get_frame_texture(animation, frame);
  226. if (texture.is_null()) {
  227. return;
  228. }
  229. RID ci = get_canvas_item();
  230. Size2 s = texture->get_size();
  231. Point2 ofs = offset;
  232. if (centered) {
  233. ofs -= s / 2;
  234. }
  235. if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
  236. ofs = (ofs + Point2(0.5, 0.5)).floor();
  237. }
  238. Rect2 dst_rect(ofs, s);
  239. if (hflip) {
  240. dst_rect.size.x = -dst_rect.size.x;
  241. }
  242. if (vflip) {
  243. dst_rect.size.y = -dst_rect.size.y;
  244. }
  245. texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false);
  246. } break;
  247. }
  248. }
  249. void AnimatedSprite2D::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
  250. if (frames == p_frames) {
  251. return;
  252. }
  253. if (frames.is_valid()) {
  254. frames->disconnect(CoreStringName(changed), callable_mp(this, &AnimatedSprite2D::_res_changed));
  255. }
  256. stop();
  257. frames = p_frames;
  258. if (frames.is_valid()) {
  259. frames->connect(CoreStringName(changed), callable_mp(this, &AnimatedSprite2D::_res_changed));
  260. List<StringName> al;
  261. frames->get_animation_list(&al);
  262. if (al.size() == 0) {
  263. set_animation(StringName());
  264. autoplay = String();
  265. } else {
  266. if (!frames->has_animation(animation)) {
  267. set_animation(al.front()->get());
  268. }
  269. if (!frames->has_animation(autoplay)) {
  270. autoplay = String();
  271. }
  272. }
  273. }
  274. notify_property_list_changed();
  275. queue_redraw();
  276. update_configuration_warnings();
  277. emit_signal("sprite_frames_changed");
  278. }
  279. Ref<SpriteFrames> AnimatedSprite2D::get_sprite_frames() const {
  280. return frames;
  281. }
  282. void AnimatedSprite2D::set_frame(int p_frame) {
  283. set_frame_and_progress(p_frame, signbit(get_playing_speed()) ? 1.0 : 0.0);
  284. }
  285. int AnimatedSprite2D::get_frame() const {
  286. return frame;
  287. }
  288. void AnimatedSprite2D::set_frame_progress(real_t p_progress) {
  289. frame_progress = p_progress;
  290. }
  291. real_t AnimatedSprite2D::get_frame_progress() const {
  292. return frame_progress;
  293. }
  294. void AnimatedSprite2D::set_frame_and_progress(int p_frame, real_t p_progress) {
  295. if (frames.is_null()) {
  296. return;
  297. }
  298. bool has_animation = frames->has_animation(animation);
  299. int end_frame = has_animation ? MAX(0, frames->get_frame_count(animation) - 1) : 0;
  300. bool is_changed = frame != p_frame;
  301. if (p_frame < 0) {
  302. frame = 0;
  303. } else if (has_animation && p_frame > end_frame) {
  304. frame = end_frame;
  305. } else {
  306. frame = p_frame;
  307. }
  308. _calc_frame_speed_scale();
  309. frame_progress = p_progress;
  310. if (!is_changed) {
  311. return; // No change, don't redraw.
  312. }
  313. queue_redraw();
  314. emit_signal(SceneStringName(frame_changed));
  315. }
  316. void AnimatedSprite2D::set_speed_scale(float p_speed_scale) {
  317. speed_scale = p_speed_scale;
  318. }
  319. float AnimatedSprite2D::get_speed_scale() const {
  320. return speed_scale;
  321. }
  322. float AnimatedSprite2D::get_playing_speed() const {
  323. if (!playing) {
  324. return 0;
  325. }
  326. return speed_scale * custom_speed_scale;
  327. }
  328. void AnimatedSprite2D::set_centered(bool p_center) {
  329. if (centered == p_center) {
  330. return;
  331. }
  332. centered = p_center;
  333. queue_redraw();
  334. item_rect_changed();
  335. }
  336. bool AnimatedSprite2D::is_centered() const {
  337. return centered;
  338. }
  339. void AnimatedSprite2D::set_offset(const Point2 &p_offset) {
  340. if (offset == p_offset) {
  341. return;
  342. }
  343. offset = p_offset;
  344. queue_redraw();
  345. item_rect_changed();
  346. }
  347. Point2 AnimatedSprite2D::get_offset() const {
  348. return offset;
  349. }
  350. void AnimatedSprite2D::set_flip_h(bool p_flip) {
  351. if (hflip == p_flip) {
  352. return;
  353. }
  354. hflip = p_flip;
  355. queue_redraw();
  356. }
  357. bool AnimatedSprite2D::is_flipped_h() const {
  358. return hflip;
  359. }
  360. void AnimatedSprite2D::set_flip_v(bool p_flip) {
  361. if (vflip == p_flip) {
  362. return;
  363. }
  364. vflip = p_flip;
  365. queue_redraw();
  366. }
  367. bool AnimatedSprite2D::is_flipped_v() const {
  368. return vflip;
  369. }
  370. void AnimatedSprite2D::_res_changed() {
  371. set_frame_and_progress(frame, frame_progress);
  372. queue_redraw();
  373. notify_property_list_changed();
  374. }
  375. bool AnimatedSprite2D::is_playing() const {
  376. return playing;
  377. }
  378. void AnimatedSprite2D::set_autoplay(const String &p_name) {
  379. if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
  380. WARN_PRINT("Setting autoplay after the node has been added to the scene has no effect.");
  381. }
  382. autoplay = p_name;
  383. }
  384. String AnimatedSprite2D::get_autoplay() const {
  385. return autoplay;
  386. }
  387. void AnimatedSprite2D::play(const StringName &p_name, float p_custom_scale, bool p_from_end) {
  388. StringName name = p_name;
  389. if (name == StringName()) {
  390. name = animation;
  391. }
  392. ERR_FAIL_COND_MSG(frames.is_null(), vformat("There is no animation with name '%s'.", name));
  393. ERR_FAIL_COND_MSG(!frames->get_animation_names().has(name), vformat("There is no animation with name '%s'.", name));
  394. if (frames->get_frame_count(name) == 0) {
  395. return;
  396. }
  397. playing = true;
  398. custom_speed_scale = p_custom_scale;
  399. if (name != animation) {
  400. animation = name;
  401. int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
  402. if (p_from_end) {
  403. set_frame_and_progress(end_frame, 1.0);
  404. } else {
  405. set_frame_and_progress(0, 0.0);
  406. }
  407. emit_signal(SceneStringName(animation_changed));
  408. } else {
  409. int end_frame = MAX(0, frames->get_frame_count(animation) - 1);
  410. bool is_backward = signbit(speed_scale * custom_speed_scale);
  411. if (p_from_end && is_backward && frame == 0 && frame_progress <= 0.0) {
  412. set_frame_and_progress(end_frame, 1.0);
  413. } else if (!p_from_end && !is_backward && frame == end_frame && frame_progress >= 1.0) {
  414. set_frame_and_progress(0, 0.0);
  415. }
  416. }
  417. set_process_internal(true);
  418. notify_property_list_changed();
  419. queue_redraw();
  420. }
  421. void AnimatedSprite2D::play_backwards(const StringName &p_name) {
  422. play(p_name, -1, true);
  423. }
  424. void AnimatedSprite2D::_stop_internal(bool p_reset) {
  425. playing = false;
  426. if (p_reset) {
  427. custom_speed_scale = 1.0;
  428. set_frame_and_progress(0, 0.0);
  429. }
  430. notify_property_list_changed();
  431. set_process_internal(false);
  432. }
  433. void AnimatedSprite2D::pause() {
  434. _stop_internal(false);
  435. }
  436. void AnimatedSprite2D::stop() {
  437. _stop_internal(true);
  438. }
  439. double AnimatedSprite2D::_get_frame_duration() {
  440. if (frames.is_valid() && frames->has_animation(animation)) {
  441. return frames->get_frame_duration(animation, frame);
  442. }
  443. return 1.0;
  444. }
  445. void AnimatedSprite2D::_calc_frame_speed_scale() {
  446. frame_speed_scale = 1.0 / _get_frame_duration();
  447. }
  448. void AnimatedSprite2D::set_animation(const StringName &p_name) {
  449. if (animation == p_name) {
  450. return;
  451. }
  452. animation = p_name;
  453. emit_signal(SceneStringName(animation_changed));
  454. if (frames.is_null()) {
  455. animation = StringName();
  456. stop();
  457. ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
  458. }
  459. int frame_count = frames->get_frame_count(animation);
  460. if (animation == StringName() || frame_count == 0) {
  461. stop();
  462. return;
  463. } else if (!frames->get_animation_names().has(animation)) {
  464. animation = StringName();
  465. stop();
  466. ERR_FAIL_MSG(vformat("There is no animation with name '%s'.", p_name));
  467. }
  468. if (signbit(get_playing_speed())) {
  469. set_frame_and_progress(frame_count - 1, 1.0);
  470. } else {
  471. set_frame_and_progress(0, 0.0);
  472. }
  473. notify_property_list_changed();
  474. queue_redraw();
  475. }
  476. StringName AnimatedSprite2D::get_animation() const {
  477. return animation;
  478. }
  479. PackedStringArray AnimatedSprite2D::get_configuration_warnings() const {
  480. PackedStringArray warnings = Node2D::get_configuration_warnings();
  481. if (frames.is_null()) {
  482. warnings.push_back(RTR("A SpriteFrames resource must be created or set in the \"Sprite Frames\" property in order for AnimatedSprite2D to display frames."));
  483. }
  484. return warnings;
  485. }
  486. #ifdef TOOLS_ENABLED
  487. void AnimatedSprite2D::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  488. const String pf = p_function;
  489. if (p_idx == 0 && frames.is_valid()) {
  490. if (pf == "play" || pf == "play_backwards" || pf == "set_animation" || pf == "set_autoplay") {
  491. List<StringName> al;
  492. frames->get_animation_list(&al);
  493. for (const StringName &name : al) {
  494. r_options->push_back(String(name).quote());
  495. }
  496. }
  497. }
  498. Node2D::get_argument_options(p_function, p_idx, r_options);
  499. }
  500. #endif // TOOLS_ENABLED
  501. #ifndef DISABLE_DEPRECATED
  502. bool AnimatedSprite2D::_set(const StringName &p_name, const Variant &p_value) {
  503. if ((p_name == SNAME("frames"))) {
  504. set_sprite_frames(p_value);
  505. return true;
  506. }
  507. return false;
  508. }
  509. #endif
  510. void AnimatedSprite2D::_bind_methods() {
  511. ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite2D::set_sprite_frames);
  512. ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite2D::get_sprite_frames);
  513. ClassDB::bind_method(D_METHOD("set_animation", "name"), &AnimatedSprite2D::set_animation);
  514. ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite2D::get_animation);
  515. ClassDB::bind_method(D_METHOD("set_autoplay", "name"), &AnimatedSprite2D::set_autoplay);
  516. ClassDB::bind_method(D_METHOD("get_autoplay"), &AnimatedSprite2D::get_autoplay);
  517. ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite2D::is_playing);
  518. ClassDB::bind_method(D_METHOD("play", "name", "custom_speed", "from_end"), &AnimatedSprite2D::play, DEFVAL(StringName()), DEFVAL(1.0), DEFVAL(false));
  519. ClassDB::bind_method(D_METHOD("play_backwards", "name"), &AnimatedSprite2D::play_backwards, DEFVAL(StringName()));
  520. ClassDB::bind_method(D_METHOD("pause"), &AnimatedSprite2D::pause);
  521. ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite2D::stop);
  522. ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite2D::set_centered);
  523. ClassDB::bind_method(D_METHOD("is_centered"), &AnimatedSprite2D::is_centered);
  524. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &AnimatedSprite2D::set_offset);
  525. ClassDB::bind_method(D_METHOD("get_offset"), &AnimatedSprite2D::get_offset);
  526. ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &AnimatedSprite2D::set_flip_h);
  527. ClassDB::bind_method(D_METHOD("is_flipped_h"), &AnimatedSprite2D::is_flipped_h);
  528. ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &AnimatedSprite2D::set_flip_v);
  529. ClassDB::bind_method(D_METHOD("is_flipped_v"), &AnimatedSprite2D::is_flipped_v);
  530. ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite2D::set_frame);
  531. ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite2D::get_frame);
  532. ClassDB::bind_method(D_METHOD("set_frame_progress", "progress"), &AnimatedSprite2D::set_frame_progress);
  533. ClassDB::bind_method(D_METHOD("get_frame_progress"), &AnimatedSprite2D::get_frame_progress);
  534. ClassDB::bind_method(D_METHOD("set_frame_and_progress", "frame", "progress"), &AnimatedSprite2D::set_frame_and_progress);
  535. ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite2D::set_speed_scale);
  536. ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite2D::get_speed_scale);
  537. ClassDB::bind_method(D_METHOD("get_playing_speed"), &AnimatedSprite2D::get_playing_speed);
  538. ADD_SIGNAL(MethodInfo("sprite_frames_changed"));
  539. ADD_SIGNAL(MethodInfo("animation_changed"));
  540. ADD_SIGNAL(MethodInfo("frame_changed"));
  541. ADD_SIGNAL(MethodInfo("animation_looped"));
  542. ADD_SIGNAL(MethodInfo("animation_finished"));
  543. ADD_GROUP("Animation", "");
  544. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sprite_frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
  545. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "animation", PROPERTY_HINT_ENUM, ""), "set_animation", "get_animation");
  546. ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_autoplay", "get_autoplay");
  547. ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame");
  548. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "frame_progress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_frame_progress", "get_frame_progress");
  549. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale"), "set_speed_scale", "get_speed_scale");
  550. ADD_GROUP("Offset", "");
  551. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
  552. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset", PROPERTY_HINT_NONE, "suffix:px"), "set_offset", "get_offset");
  553. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
  554. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
  555. }
  556. AnimatedSprite2D::AnimatedSprite2D() {
  557. }