LevelHomeCoin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const DWTool = require('../utils/DWTool');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. coinNode: cc.Node,
  6. totalRateLabel: cc.Label,
  7. coinCount: 0,
  8. totalRate: {
  9. get: function() {
  10. if (!this._totalRate) {
  11. this._totalRate = 0;
  12. }
  13. return this._totalRate;
  14. },
  15. set: function(value) {
  16. this._totalRate = value;
  17. this.totalRateLabel.string = DWTool.coinParse(this._totalRate);
  18. }
  19. },
  20. coinSpine: sp.Skeleton,
  21. isPlay: false,
  22. isPlaying: false,
  23. },
  24. // LIFE-CYCLE CALLBACKS:
  25. onLoad () {
  26. },
  27. getOwner() {
  28. return this.node;
  29. },
  30. /**
  31. * 初始化静态金币Spine动画
  32. * @param {Number} coinIndex 金币下标,默认[0,1,2]
  33. */
  34. initStatic(coinIndex) {
  35. let animKeyArray = ['jinbi_1', 'jinbi_2', 'jinbi_3'];
  36. let animKey;
  37. if(coinIndex <= animKeyArray.length - 1) {
  38. animKey = animKeyArray[coinIndex]
  39. } else {
  40. animKey = coinIndex % animKeyArray.length;
  41. }
  42. this.coinSpine.setAnimation(0, animKey, true)
  43. },
  44. /**
  45. * 初始化飞行金币Spine动画
  46. */
  47. initAnim() {
  48. let animKeyArray = ['jinbi_zhuangdong1', 'jinbi_zhuangdong2', 'jinbi_zhuangdong3']
  49. //随机设置转动动画
  50. let ran = Math.floor(Math.random() * 3);
  51. let animKey = animKeyArray[ran]
  52. this.totalRateLabel.node.active = false;
  53. this.coinSpine.setAnimation(0, animKey, true)
  54. },
  55. showAnimation() {
  56. if (this.isPlaying) { return; }
  57. this.node.stopAllActions();
  58. this.node.active = true;
  59. this.isPlayed = true;
  60. this.isPlaying = true;
  61. let jumpHeight = 175;
  62. let duration = 0.3;
  63. let animationArray = [];
  64. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  65. let moveAction2 = cc.moveBy(duration, 0, -95).easing(cc.easeCubicActionIn());
  66. animationArray.push(moveAction1);
  67. animationArray.push(moveAction2);
  68. while(jumpHeight > 0.1) {
  69. jumpHeight = jumpHeight - (jumpHeight / 3);
  70. duration = duration - (duration / 3);
  71. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  72. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  73. animationArray.push(upAction);
  74. animationArray.push(downAction);
  75. }
  76. let callback = cc.callFunc(() => {
  77. this.isPlaying = false;
  78. });
  79. animationArray.push(callback);
  80. this.node.runAction(cc.sequence(animationArray));
  81. },
  82. updateAnimation() {
  83. if (this.isPlaying) { return; }
  84. this.node.stopAllActions();
  85. this.isPlaying = true;
  86. let upAction = cc.moveBy(0.1, 0, 30);
  87. let downAction = cc.moveBy(0.1, 0, -30);
  88. let callback = cc.callFunc(() => {
  89. this.isPlaying = false;
  90. });
  91. this.coinNode.runAction(cc.sequence(upAction, downAction, callback));
  92. },
  93. start () {
  94. },
  95. // update (dt) {},
  96. });