animated_sprite_2d.cpp 19 KB

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