animated_sprite.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*************************************************************************/
  2. /* animated_sprite.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  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.h"
  31. #include "os/os.h"
  32. #include "scene/scene_string_names.h"
  33. #define NORMAL_SUFFIX "_normal"
  34. ////////////////////////////
  35. void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) {
  36. Map<StringName, Anim>::Element *E = animations.find(p_anim);
  37. ERR_FAIL_COND(!E);
  38. if (p_at_pos >= 0 && p_at_pos < E->get().frames.size())
  39. E->get().frames.insert(p_at_pos, p_frame);
  40. else
  41. E->get().frames.push_back(p_frame);
  42. emit_changed();
  43. }
  44. int SpriteFrames::get_frame_count(const StringName &p_anim) const {
  45. const Map<StringName, Anim>::Element *E = animations.find(p_anim);
  46. ERR_FAIL_COND_V(!E, 0);
  47. return E->get().frames.size();
  48. }
  49. void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) {
  50. Map<StringName, Anim>::Element *E = animations.find(p_anim);
  51. ERR_FAIL_COND(!E);
  52. E->get().frames.remove(p_idx);
  53. emit_changed();
  54. }
  55. void SpriteFrames::clear(const StringName &p_anim) {
  56. Map<StringName, Anim>::Element *E = animations.find(p_anim);
  57. ERR_FAIL_COND(!E);
  58. E->get().frames.clear();
  59. emit_changed();
  60. }
  61. void SpriteFrames::clear_all() {
  62. animations.clear();
  63. add_animation("default");
  64. }
  65. void SpriteFrames::add_animation(const StringName &p_anim) {
  66. ERR_FAIL_COND(animations.has(p_anim));
  67. animations[p_anim] = Anim();
  68. animations[p_anim].normal_name = String(p_anim) + NORMAL_SUFFIX;
  69. }
  70. bool SpriteFrames::has_animation(const StringName &p_anim) const {
  71. return animations.has(p_anim);
  72. }
  73. void SpriteFrames::remove_animation(const StringName &p_anim) {
  74. animations.erase(p_anim);
  75. }
  76. void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &p_next) {
  77. ERR_FAIL_COND(!animations.has(p_prev));
  78. ERR_FAIL_COND(animations.has(p_next));
  79. Anim anim = animations[p_prev];
  80. animations.erase(p_prev);
  81. animations[p_next] = anim;
  82. animations[p_next].normal_name = String(p_next) + NORMAL_SUFFIX;
  83. }
  84. Vector<String> SpriteFrames::_get_animation_list() const {
  85. Vector<String> ret;
  86. List<StringName> al;
  87. get_animation_list(&al);
  88. for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
  89. ret.push_back(E->get());
  90. }
  91. return ret;
  92. }
  93. void SpriteFrames::get_animation_list(List<StringName> *r_animations) const {
  94. for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) {
  95. r_animations->push_back(E->key());
  96. }
  97. }
  98. void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) {
  99. ERR_FAIL_COND(p_fps < 0);
  100. Map<StringName, Anim>::Element *E = animations.find(p_anim);
  101. ERR_FAIL_COND(!E);
  102. E->get().speed = p_fps;
  103. }
  104. float SpriteFrames::get_animation_speed(const StringName &p_anim) const {
  105. const Map<StringName, Anim>::Element *E = animations.find(p_anim);
  106. ERR_FAIL_COND_V(!E, 0);
  107. return E->get().speed;
  108. }
  109. void SpriteFrames::set_animation_loop(const StringName &p_anim, bool p_loop) {
  110. Map<StringName, Anim>::Element *E = animations.find(p_anim);
  111. ERR_FAIL_COND(!E);
  112. E->get().loop = p_loop;
  113. }
  114. bool SpriteFrames::get_animation_loop(const StringName &p_anim) const {
  115. const Map<StringName, Anim>::Element *E = animations.find(p_anim);
  116. ERR_FAIL_COND_V(!E, false);
  117. return E->get().loop;
  118. }
  119. void SpriteFrames::_set_frames(const Array &p_frames) {
  120. clear_all();
  121. Map<StringName, Anim>::Element *E = animations.find(SceneStringNames::get_singleton()->_default);
  122. ERR_FAIL_COND(!E);
  123. E->get().frames.resize(p_frames.size());
  124. for (int i = 0; i < E->get().frames.size(); i++)
  125. E->get().frames[i] = p_frames[i];
  126. }
  127. Array SpriteFrames::_get_frames() const {
  128. return Array();
  129. }
  130. Array SpriteFrames::_get_animations() const {
  131. Array anims;
  132. for (Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) {
  133. Dictionary d;
  134. d["name"] = E->key();
  135. d["speed"] = E->get().speed;
  136. d["loop"] = E->get().loop;
  137. Array frames;
  138. for (int i = 0; i < E->get().frames.size(); i++) {
  139. frames.push_back(E->get().frames[i]);
  140. }
  141. d["frames"] = frames;
  142. anims.push_back(d);
  143. }
  144. return anims;
  145. }
  146. void SpriteFrames::_set_animations(const Array &p_animations) {
  147. animations.clear();
  148. for (int i = 0; i < p_animations.size(); i++) {
  149. Dictionary d = p_animations[i];
  150. ERR_CONTINUE(!d.has("name"));
  151. ERR_CONTINUE(!d.has("speed"));
  152. ERR_CONTINUE(!d.has("loop"));
  153. ERR_CONTINUE(!d.has("frames"));
  154. Anim anim;
  155. anim.speed = d["speed"];
  156. anim.loop = d["loop"];
  157. Array frames = d["frames"];
  158. for (int i = 0; i < frames.size(); i++) {
  159. RES res = frames[i];
  160. anim.frames.push_back(res);
  161. }
  162. animations[d["name"]] = anim;
  163. }
  164. }
  165. void SpriteFrames::_bind_methods() {
  166. ClassDB::bind_method(D_METHOD("add_animation", "anim"), &SpriteFrames::add_animation);
  167. ClassDB::bind_method(D_METHOD("has_animation", "anim"), &SpriteFrames::has_animation);
  168. ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation);
  169. ClassDB::bind_method(D_METHOD("rename_animation", "anim", "newname"), &SpriteFrames::rename_animation);
  170. ClassDB::bind_method(D_METHOD("set_animation_speed", "anim", "speed"), &SpriteFrames::set_animation_speed);
  171. ClassDB::bind_method(D_METHOD("get_animation_speed", "anim"), &SpriteFrames::get_animation_speed);
  172. ClassDB::bind_method(D_METHOD("set_animation_loop", "anim", "loop"), &SpriteFrames::set_animation_loop);
  173. ClassDB::bind_method(D_METHOD("get_animation_loop", "anim"), &SpriteFrames::get_animation_loop);
  174. ClassDB::bind_method(D_METHOD("add_frame", "anim", "frame", "at_position"), &SpriteFrames::add_frame, DEFVAL(-1));
  175. ClassDB::bind_method(D_METHOD("get_frame_count", "anim"), &SpriteFrames::get_frame_count);
  176. ClassDB::bind_method(D_METHOD("get_frame", "anim", "idx"), &SpriteFrames::get_frame);
  177. ClassDB::bind_method(D_METHOD("set_frame", "anim", "idx", "txt"), &SpriteFrames::set_frame);
  178. ClassDB::bind_method(D_METHOD("remove_frame", "anim", "idx"), &SpriteFrames::remove_frame);
  179. ClassDB::bind_method(D_METHOD("clear", "anim"), &SpriteFrames::clear);
  180. ClassDB::bind_method(D_METHOD("clear_all"), &SpriteFrames::clear_all);
  181. ClassDB::bind_method(D_METHOD("_set_frames"), &SpriteFrames::_set_frames);
  182. ClassDB::bind_method(D_METHOD("_get_frames"), &SpriteFrames::_get_frames);
  183. ADD_PROPERTYNZ(PropertyInfo(Variant::ARRAY, "frames", PROPERTY_HINT_NONE, "", 0), "_set_frames", "_get_frames"); //compatibility
  184. ClassDB::bind_method(D_METHOD("_set_animations"), &SpriteFrames::_set_animations);
  185. ClassDB::bind_method(D_METHOD("_get_animations"), &SpriteFrames::_get_animations);
  186. ADD_PROPERTYNZ(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_animations", "_get_animations"); //compatibility
  187. }
  188. SpriteFrames::SpriteFrames() {
  189. add_animation(SceneStringNames::get_singleton()->_default);
  190. }
  191. void AnimatedSprite::edit_set_pivot(const Point2 &p_pivot) {
  192. set_offset(p_pivot);
  193. }
  194. Point2 AnimatedSprite::edit_get_pivot() const {
  195. return get_offset();
  196. }
  197. bool AnimatedSprite::edit_has_pivot() const {
  198. return true;
  199. }
  200. void AnimatedSprite::_validate_property(PropertyInfo &property) const {
  201. if (!frames.is_valid())
  202. return;
  203. if (property.name == "animation") {
  204. property.hint = PROPERTY_HINT_ENUM;
  205. List<StringName> names;
  206. frames->get_animation_list(&names);
  207. names.sort_custom<StringName::AlphCompare>();
  208. bool current_found = false;
  209. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  210. if (E->prev()) {
  211. property.hint_string += ",";
  212. }
  213. property.hint_string += String(E->get());
  214. if (animation == E->get()) {
  215. current_found = true;
  216. }
  217. }
  218. if (!current_found) {
  219. if (property.hint_string == String()) {
  220. property.hint_string = String(animation);
  221. } else {
  222. property.hint_string = String(animation) + "," + property.hint_string;
  223. }
  224. }
  225. }
  226. if (property.name == "frame") {
  227. property.hint = PROPERTY_HINT_SPRITE_FRAME;
  228. if (frames->has_animation(animation) && frames->get_frame_count(animation) > 1) {
  229. property.hint_string = "0," + itos(frames->get_frame_count(animation) - 1) + ",1";
  230. }
  231. }
  232. }
  233. void AnimatedSprite::_notification(int p_what) {
  234. switch (p_what) {
  235. case NOTIFICATION_INTERNAL_PROCESS: {
  236. if (frames.is_null())
  237. return;
  238. if (!frames->has_animation(animation))
  239. return;
  240. if (frame < 0)
  241. return;
  242. float speed = frames->get_animation_speed(animation);
  243. if (speed == 0)
  244. return; //do nothing
  245. float remaining = get_process_delta_time();
  246. while (remaining) {
  247. if (timeout <= 0) {
  248. timeout = 1.0 / speed;
  249. int fc = frames->get_frame_count(animation);
  250. if (frame >= fc - 1) {
  251. if (frames->get_animation_loop(animation)) {
  252. frame = 0;
  253. } else {
  254. frame = fc - 1;
  255. }
  256. } else {
  257. frame++;
  258. if (frame == fc - 1) {
  259. emit_signal(SceneStringNames::get_singleton()->animation_finished);
  260. }
  261. }
  262. update();
  263. _change_notify("frame");
  264. emit_signal(SceneStringNames::get_singleton()->frame_changed);
  265. }
  266. float to_process = MIN(timeout, remaining);
  267. remaining -= to_process;
  268. timeout -= to_process;
  269. }
  270. } break;
  271. case NOTIFICATION_DRAW: {
  272. if (frames.is_null()) {
  273. print_line("no draw no faemos");
  274. return;
  275. }
  276. if (frame < 0) {
  277. print_line("no draw frame <0");
  278. return;
  279. }
  280. if (!frames->has_animation(animation)) {
  281. print_line("no draw no anim: " + String(animation));
  282. return;
  283. }
  284. Ref<Texture> texture = frames->get_frame(animation, frame);
  285. if (texture.is_null()) {
  286. print_line("no draw texture is null");
  287. return;
  288. }
  289. Ref<Texture> normal = frames->get_normal_frame(animation, frame);
  290. //print_line("DECIDED TO DRAW");
  291. RID ci = get_canvas_item();
  292. /*
  293. texture->draw(ci,Point2());
  294. break;
  295. */
  296. Size2i s;
  297. s = texture->get_size();
  298. Point2 ofs = offset;
  299. if (centered)
  300. ofs -= s / 2;
  301. if (Engine::get_singleton()->get_use_pixel_snap()) {
  302. ofs = ofs.floor();
  303. }
  304. Rect2 dst_rect(ofs, s);
  305. if (hflip)
  306. dst_rect.size.x = -dst_rect.size.x;
  307. if (vflip)
  308. dst_rect.size.y = -dst_rect.size.y;
  309. //texture->draw_rect(ci,dst_rect,false,modulate);
  310. texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal);
  311. //VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);
  312. } break;
  313. }
  314. }
  315. void AnimatedSprite::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
  316. if (frames.is_valid())
  317. frames->disconnect("changed", this, "_res_changed");
  318. frames = p_frames;
  319. if (frames.is_valid())
  320. frames->connect("changed", this, "_res_changed");
  321. if (!frames.is_valid()) {
  322. frame = 0;
  323. } else {
  324. set_frame(frame);
  325. }
  326. _change_notify();
  327. _reset_timeout();
  328. update();
  329. update_configuration_warning();
  330. }
  331. Ref<SpriteFrames> AnimatedSprite::get_sprite_frames() const {
  332. return frames;
  333. }
  334. void AnimatedSprite::set_frame(int p_frame) {
  335. if (!frames.is_valid()) {
  336. return;
  337. }
  338. if (frames->has_animation(animation)) {
  339. int limit = frames->get_frame_count(animation);
  340. if (p_frame >= limit)
  341. p_frame = limit - 1;
  342. }
  343. if (p_frame < 0)
  344. p_frame = 0;
  345. if (frame == p_frame)
  346. return;
  347. frame = p_frame;
  348. _reset_timeout();
  349. update();
  350. _change_notify("frame");
  351. emit_signal(SceneStringNames::get_singleton()->frame_changed);
  352. }
  353. int AnimatedSprite::get_frame() const {
  354. return frame;
  355. }
  356. void AnimatedSprite::set_centered(bool p_center) {
  357. centered = p_center;
  358. update();
  359. item_rect_changed();
  360. }
  361. bool AnimatedSprite::is_centered() const {
  362. return centered;
  363. }
  364. void AnimatedSprite::set_offset(const Point2 &p_offset) {
  365. offset = p_offset;
  366. update();
  367. item_rect_changed();
  368. _change_notify("offset");
  369. }
  370. Point2 AnimatedSprite::get_offset() const {
  371. return offset;
  372. }
  373. void AnimatedSprite::set_flip_h(bool p_flip) {
  374. hflip = p_flip;
  375. update();
  376. }
  377. bool AnimatedSprite::is_flipped_h() const {
  378. return hflip;
  379. }
  380. void AnimatedSprite::set_flip_v(bool p_flip) {
  381. vflip = p_flip;
  382. update();
  383. }
  384. bool AnimatedSprite::is_flipped_v() const {
  385. return vflip;
  386. }
  387. Rect2 AnimatedSprite::get_item_rect() const {
  388. if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
  389. return Node2D::get_item_rect();
  390. }
  391. Ref<Texture> t;
  392. if (animation)
  393. t = frames->get_frame(animation, frame);
  394. if (t.is_null())
  395. return Node2D::get_item_rect();
  396. Size2i s = t->get_size();
  397. Point2 ofs = offset;
  398. if (centered)
  399. ofs -= s / 2;
  400. if (s == Size2(0, 0))
  401. s = Size2(1, 1);
  402. return Rect2(ofs, s);
  403. }
  404. void AnimatedSprite::_res_changed() {
  405. set_frame(frame);
  406. _change_notify("frame");
  407. _change_notify("animation");
  408. update();
  409. }
  410. void AnimatedSprite::_set_playing(bool p_playing) {
  411. if (playing == p_playing)
  412. return;
  413. playing = p_playing;
  414. _reset_timeout();
  415. set_process_internal(playing);
  416. }
  417. bool AnimatedSprite::_is_playing() const {
  418. return playing;
  419. }
  420. void AnimatedSprite::play(const StringName &p_animation) {
  421. if (p_animation)
  422. set_animation(p_animation);
  423. _set_playing(true);
  424. }
  425. void AnimatedSprite::stop() {
  426. _set_playing(false);
  427. }
  428. bool AnimatedSprite::is_playing() const {
  429. return is_processing();
  430. }
  431. void AnimatedSprite::_reset_timeout() {
  432. if (!playing)
  433. return;
  434. if (frames.is_valid() && frames->has_animation(animation)) {
  435. float speed = frames->get_animation_speed(animation);
  436. if (speed > 0) {
  437. timeout = 1.0 / speed;
  438. } else {
  439. timeout = 0;
  440. }
  441. } else {
  442. timeout = 0;
  443. }
  444. }
  445. void AnimatedSprite::set_animation(const StringName &p_animation) {
  446. if (animation == p_animation)
  447. return;
  448. animation = p_animation;
  449. _reset_timeout();
  450. set_frame(0);
  451. _change_notify();
  452. update();
  453. }
  454. StringName AnimatedSprite::get_animation() const {
  455. return animation;
  456. }
  457. String AnimatedSprite::get_configuration_warning() const {
  458. if (frames.is_null()) {
  459. return TTR("A SpriteFrames resource must be created or set in the 'Frames' property in order for AnimatedSprite to display frames.");
  460. }
  461. return String();
  462. }
  463. void AnimatedSprite::_bind_methods() {
  464. ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite::set_sprite_frames);
  465. ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite::get_sprite_frames);
  466. ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite::set_animation);
  467. ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite::get_animation);
  468. ClassDB::bind_method(D_METHOD("_set_playing", "playing"), &AnimatedSprite::_set_playing);
  469. ClassDB::bind_method(D_METHOD("_is_playing"), &AnimatedSprite::_is_playing);
  470. ClassDB::bind_method(D_METHOD("play", "anim"), &AnimatedSprite::play, DEFVAL(StringName()));
  471. ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite::stop);
  472. ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite::is_playing);
  473. ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite::set_centered);
  474. ClassDB::bind_method(D_METHOD("is_centered"), &AnimatedSprite::is_centered);
  475. ClassDB::bind_method(D_METHOD("set_offset", "offset"), &AnimatedSprite::set_offset);
  476. ClassDB::bind_method(D_METHOD("get_offset"), &AnimatedSprite::get_offset);
  477. ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &AnimatedSprite::set_flip_h);
  478. ClassDB::bind_method(D_METHOD("is_flipped_h"), &AnimatedSprite::is_flipped_h);
  479. ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &AnimatedSprite::set_flip_v);
  480. ClassDB::bind_method(D_METHOD("is_flipped_v"), &AnimatedSprite::is_flipped_v);
  481. ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame);
  482. ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame);
  483. ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite::_res_changed);
  484. ADD_SIGNAL(MethodInfo("frame_changed"));
  485. ADD_SIGNAL(MethodInfo("animation_finished"));
  486. ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
  487. ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
  488. ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
  489. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
  490. ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
  491. ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
  492. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
  493. ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
  494. }
  495. AnimatedSprite::AnimatedSprite() {
  496. centered = true;
  497. hflip = false;
  498. vflip = false;
  499. frame = 0;
  500. playing = false;
  501. animation = "default";
  502. timeout = 0;
  503. }