LevelHomeCoin.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. index: 0,
  24. },
  25. // LIFE-CYCLE CALLBACKS:
  26. onLoad () {
  27. },
  28. getOwner() {
  29. return this.node;
  30. },
  31. /**
  32. * 初始化静态金币Spine动画
  33. * @param {Number} coinIndex 金币下标,默认[0,1,2]
  34. */
  35. initStatic(coinIndex) {
  36. let animKeyArray = ['jinbi_1', 'jinbi_2', 'jinbi_3'];
  37. let animKey;
  38. if(coinIndex <= animKeyArray.length - 1) {
  39. animKey = animKeyArray[coinIndex]
  40. } else {
  41. animKey = coinIndex % animKeyArray.length;
  42. }
  43. this.coinSpine.setAnimation(0, animKey, true)
  44. },
  45. /**
  46. * 初始化飞行金币Spine动画
  47. */
  48. initAnim() {
  49. let animKeyArray = ['jinbi_zhuangdong1', 'jinbi_zhuangdong2', 'jinbi_zhuangdong3']
  50. //随机设置转动动画
  51. let ran = Math.floor(Math.random() * 3);
  52. let animKey = animKeyArray[ran]
  53. this.totalRateLabel.node.active = false;
  54. this.coinSpine.setAnimation(0, animKey, true)
  55. },
  56. showAnimation() {
  57. if (this.isPlaying) { return; }
  58. this.node.stopAllActions();
  59. this.node.active = true;
  60. this.isPlayed = true;
  61. this.isPlaying = true;
  62. let jumpHeight = 175;
  63. let duration = 0.3;
  64. let animationArray = [];
  65. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  66. let moveAction2 = cc.moveBy(duration, 0, -95).easing(cc.easeCubicActionIn());
  67. animationArray.push(moveAction1);
  68. animationArray.push(moveAction2);
  69. while(jumpHeight > 0.1) {
  70. jumpHeight = jumpHeight - (jumpHeight / 3);
  71. duration = duration - (duration / 3);
  72. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  73. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  74. animationArray.push(upAction);
  75. animationArray.push(downAction);
  76. }
  77. let callback = cc.callFunc(() => {
  78. this.isPlaying = false;
  79. });
  80. animationArray.push(callback);
  81. this.node.runAction(cc.sequence(animationArray));
  82. },
  83. updateAnimation() {
  84. if (this.isPlaying) { return; }
  85. this.node.stopAllActions();
  86. this.isPlaying = true;
  87. let upAction = cc.moveBy(0.1, 0, 30);
  88. let downAction = cc.moveBy(0.1, 0, -30);
  89. let callback = cc.callFunc(() => {
  90. this.isPlaying = false;
  91. });
  92. this.coinNode.runAction(cc.sequence(upAction, downAction, callback));
  93. },
  94. start () {
  95. },
  96. // update (dt) {},
  97. });