loopTime.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. window.boxingManager = {
  2. // confs: [
  3. // {
  4. // top: {
  5. // time: 0.2,
  6. // timeScale: 3
  7. // },
  8. // mid: {
  9. // time: 2.6,
  10. // timeScale: 1
  11. // },
  12. // lower: {
  13. // time: 0.1,
  14. // timeScale: 3
  15. // },
  16. // },
  17. // {
  18. // top: {
  19. // time: 0.2,
  20. // timeScale: 3
  21. // },
  22. // mid: {
  23. // time: 2.2,
  24. // timeScale: 1
  25. // },
  26. // lower: {
  27. // time: 0.1,
  28. // timeScale: 3
  29. // }
  30. // },
  31. // {
  32. // top: {
  33. // time: 0.2,
  34. // timeScale: 3
  35. // },
  36. // mid: {
  37. // time: 2,
  38. // timeScale: 1
  39. // },
  40. // lower: {
  41. // time: 0.1,
  42. // timeScale: 3
  43. // }
  44. // },
  45. //
  46. // ],
  47. scheduleTimes : [3,1.5,1.25],
  48. num: 0,
  49. //奖励分数
  50. rewardScore : 10,
  51. setConf: function (num) {
  52. this.num = num;
  53. return this.confs[this.num];
  54. },
  55. getConf: function () {
  56. return this.confs[this.num];
  57. },
  58. setScheduleTimes: function (num) {
  59. this.num = num;
  60. return this.scheduleTimes[this.num];
  61. },
  62. getScheduleTimes: function () {
  63. // Log.info("到底是什么",this.num,this.scheduleTimes)
  64. return this.scheduleTimes[this.num];
  65. },
  66. }
  67. cc.Class({
  68. extends: cc.Component,
  69. properties: {
  70. },
  71. onLoad() {
  72. },
  73. endLoop: function () {
  74. },
  75. startLoop: function () {
  76. this.count = boxingManager.getScheduleTimes();
  77. this.callback = function () {
  78. if (this.count != boxingManager.getScheduleTimes()) {
  79. // 在第六次执行回调时取消这个计时器
  80. this.count = boxingManager.getScheduleTimes();
  81. this.unschedule(this.callback);
  82. this.startLoop();
  83. return;
  84. }
  85. // let time = new Date().getTime();
  86. // // console.log("相差时间 ",time-this.currld);
  87. // this.currld = time;
  88. this.doSomething();
  89. // this.startLoop();
  90. // this.count++;
  91. }
  92. this.schedule(this.callback, boxingManager.getScheduleTimes());
  93. },
  94. doSomething: function () {
  95. if (this.StartLoopListener) {
  96. this.StartLoopListener()
  97. }
  98. },
  99. start() {
  100. },
  101. setStartLoopListener(StartLoopListener){
  102. this.StartLoopListener = StartLoopListener;
  103. },
  104. update(dt) {
  105. },
  106. });