matchText.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. this.zhao = UtilsNode.getNode("zhao",this.node);
  33. this.waittimeText = UtilsNode.getNode("waittimeText",this.node);
  34. this.waittime = UtilsNode.getNode("waittime",this.node);
  35. this.chenggong = UtilsNode.getNode("chenggong",this.node);
  36. },
  37. //开始倒计时
  38. startCountDownTime: function () {
  39. // this.stopCountDownTime()
  40. this.chenggong.active = false;
  41. this.waittime.active = true;
  42. this.waittimeText.active = true;
  43. this.zhao.active = true;
  44. this.timeData = {
  45. branch: "00",
  46. second: "00"
  47. }
  48. this.waittime.getComponent(cc.Label).string = this.timeData.branch + ":" + this.timeData.second
  49. this.time_count = 0;
  50. this.time_branch = 0;
  51. this.time_second = 0;
  52. this.callbackCountDownTime = function () {
  53. this.time_second++;
  54. if (this.time_second > 60) {
  55. this.time_second = 0;
  56. this.time_branch++;
  57. }
  58. this.time_count++;
  59. //设置秒
  60. var second;
  61. if (this.time_second < 10) {
  62. second = '0' + this.time_second;
  63. } else {
  64. second = this.time_second;
  65. }
  66. this.timeData.second = second + "";
  67. var branch;
  68. if (this.time_branch < 10) {
  69. branch = '0' + this.time_branch;
  70. } else {
  71. branch = this.time_branch;
  72. }
  73. this.timeData.branch = branch + "";
  74. // console.log("我们的时间", this.timeData);
  75. this.updetaTime(this.timeData);
  76. }
  77. this.schedule(this.callbackCountDownTime, 1);
  78. },
  79. updetaTime: function (timeData) {
  80. this.waittime.getComponent(cc.Label).string = timeData.branch + ":" + timeData.second
  81. },
  82. //停止倒计时
  83. stopCountDownTime: function () {
  84. this.unschedule(this.callbackCountDownTime);
  85. this.chenggong.active = false;
  86. this.waittime.active = false;
  87. this.zhao.active = false;
  88. this.waittimeText.active = false;
  89. },
  90. succeed(){
  91. this.chenggong.active = true;
  92. this.waittime.active = false;
  93. this.zhao.active = false;
  94. this.waittimeText.active = false;
  95. }
  96. // update (dt) {},
  97. });