animated_sprite_2d.cpp 20 KB

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