ClickAddMoneyCoin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const GameModule = require("../utils/GameModule");
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. coinSkeleton: sp.Skeleton,
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. this.isPlaying = false;
  10. var sd = this.coinSkeleton.skeletonData.getRuntimeData(true);
  11. this.hitAnimations = sd.animations.filter(item => item.name.indexOf('jinbi_hit') != -1).map(animation => animation.name) || [];
  12. },
  13. showOnceCoin() {
  14. if (this.hitAnimations.length > 0) {
  15. let hitType = Math.floor(Math.random() * this.hitAnimations.length);
  16. this.coinSkeleton.setAnimation(0, this.hitAnimations[hitType], false);
  17. this.coinSkeleton.setCompleteListener(() => {
  18. this.coinSkeleton.completeListener = null;
  19. this.node.active = false;
  20. });
  21. }
  22. },
  23. showCoin(callback) {
  24. if (this.isPlaying) { return }
  25. if (this.hitAnimations.length > 0) {
  26. this.isPlaying = true;
  27. let hitType = Math.floor(Math.random() * this.hitAnimations.length);
  28. this.coinSkeleton.setAnimation(0, this.hitAnimations[hitType], false);
  29. setTimeout(() => {
  30. GameModule.audioMng.playUpdateBuilding();
  31. }, 200);
  32. this.coinSkeleton.setCompleteListener(() => {
  33. this.isPlaying = false;
  34. this.coinSkeleton.completeListener = null;
  35. this.node.active = false;
  36. if (callback) {
  37. callback();
  38. }
  39. });
  40. }
  41. },
  42. showAutoCoin(callback, finishCallback) {
  43. if (this.isPlaying) { return }
  44. if (this.hitAnimations.length > 0) {
  45. this.isPlaying = true;
  46. let hitType = Math.floor(Math.random() * this.hitAnimations.length);
  47. this.coinSkeleton.setAnimation(0, this.hitAnimations[hitType], false);
  48. this.coinSkeleton.setCompleteListener(() => {
  49. this.isPlaying = false;
  50. this.coinSkeleton.completeListener = null;
  51. this.node.active = false;
  52. if (finishCallback) {
  53. finishCallback();
  54. }
  55. });
  56. setTimeout(() => {
  57. if (callback) {
  58. callback();
  59. }
  60. }, 200);
  61. }
  62. },
  63. start () {
  64. },
  65. // update (dt) {},
  66. });