timebox.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. coinParticle:{
  11. default: null,
  12. type: cc.Prefab,
  13. },
  14. earnMoney:{
  15. default: null,
  16. type: cc.Prefab,
  17. },
  18. lb:{
  19. default: null,
  20. type: cc.Label,
  21. },
  22. },
  23. onLoad(){
  24. cc.game.addPersistRootNode(this.node);
  25. this.inittime();
  26. },
  27. inittime(){
  28. let _this = this;
  29. // let countDownNode = this.daojishi_string.getComponent(Label);
  30. this.lb.string = '05:00';
  31. let time = 180;
  32. this.lb.schedule(function () {
  33. time--;
  34. let minute = Math.floor(time / 60);
  35. let second = time % 60;
  36. let timeStr = minute + ":" + second;
  37. _this.lb.string = timeStr;
  38. if (time == 0) {
  39. cc.tween(_this.node)
  40. .to(1, { scale: 1.2})
  41. .to(1, { scale: 1 })
  42. .union()
  43. .repeatForever()
  44. .start();
  45. if (cc.sys.language != cc.sys.LANGUAGE_CHINESE) {
  46. _this.lb.string = "Get"
  47. } else {
  48. _this.lb.string = "领取"
  49. }
  50. }
  51. }, 1, time - 1, 0);
  52. },
  53. gettimereward(){
  54. if (cc.sys.language != cc.sys.LANGUAGE_CHINESE) {
  55. if (this.lb.string != 'Get') {
  56. return;
  57. }
  58. } else {
  59. if (this.lb.string != '领取') {
  60. return;
  61. }
  62. }
  63. let ani = this.node.getComponent(cc.Animation);
  64. ani.play();
  65. // ani.setCurrentTime(2);
  66. // register event to all animation
  67. this.finished()
  68. this.inittime();
  69. // this.node.getComponent('collect_coin_anim').onPlayCoinAni(this.node);
  70. },
  71. finished : function () {
  72. // callback
  73. console.log("finished")
  74. this.scheduleOnce(()=>{
  75. this.node.stopAllActions();
  76. this.node.getComponent(cc.Animation).stop();
  77. },1)
  78. let icon = Storage.Get_storage(Storage.GameMessageType.coin);
  79. Storage.Set_storage(Storage.GameMessageType.coin, Number(icon) + 10000);
  80. let sjb = cc.instantiate(this.coinParticle);
  81. sjb.parent = this.node;
  82. this.showCoinAdd(10000)
  83. },
  84. showCoinAdd(num) {
  85. let earnnum = cc.instantiate(this.earnMoney);
  86. earnnum.setScale(0.5);
  87. earnnum.getComponent(cc.Label).string = num;
  88. earnnum.parent = this.node;
  89. // var placeAction = cc.place(-425, 0);
  90. var actionhide = cc.hide();
  91. var actionTo = cc.jumpTo(0.5, 0, 50, 50, 1);
  92. var ActionAll = cc.sequence(actionTo, actionhide)
  93. earnnum.runAction(ActionAll);
  94. }
  95. });