BaseGameMode.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. gameStates: cc.Node,
  5. },
  6. start() {
  7. this.initgame = false; //进入游戏
  8. this.gamestart = false; //游戏开始
  9. this.gStatSt = this.gameStates.getComponent('GameStates');
  10. },
  11. startGame() {
  12. //count game time
  13. let interval = 1; // 以秒为单位的时间间隔let
  14. let repeat = cc.macro.REPEAT_FOREVER; // 重复次数
  15. let delay = 0; // 开始延时
  16. this.schedule(this.countGameTime, interval, repeat, delay);
  17. },
  18. countGameTime() {
  19. this.gStatSt.gameTime++;
  20. },
  21. millisecondToDate(msd) {
  22. var time = parseFloat(msd) / 1000; //先将毫秒转化成秒
  23. // if (null != time && "" != time) {
  24. // if (time > 60 && time < 60 * 60) {
  25. // time = parseInt(time / 60.0) + "min" + parseInt((parseFloat(time / 60.0) - parseInt(time / 60.0)) * 60) + "s";
  26. // } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
  27. // time = parseInt(time / 3600.0) + "h" + parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) + "min" + parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) - parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "s";
  28. // } else {
  29. // time = parseInt(time) + "s";
  30. // }
  31. // }
  32. if (null != time && "" != time) {
  33. if (time > 60 && time < 60 * 60) {
  34. time = parseInt(time / 60.0) + ":" + parseInt((parseFloat(time / 60.0) - parseInt(time / 60.0)) * 60) + "s";
  35. } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
  36. time = parseInt(time / 3600.0) + ":" + parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) + "min" + parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) - parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "s";
  37. } else {
  38. time = parseInt(time) + ":";
  39. }
  40. }
  41. return time;
  42. },
  43. });