Interface_game.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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: require("BaseGameStates"),
  9. properties: {
  10. timelabel: cc.Label,
  11. },
  12. // LIFE-CYCLE CALLBACKS:
  13. onLoad() {
  14. this._super();
  15. this.init();
  16. this.UiController.actions();
  17. this._game_time = this.game_time;
  18. this.timelabel.string = "01:00";
  19. if (this._game_time >= 0) {
  20. this.schedule(function() {
  21. if (this.GameMode._gamestart) { this.DoSomething(); }
  22. }, 1);
  23. }
  24. },
  25. start() {
  26. },
  27. // update (dt) {},
  28. DoSomething() { // 倒计时算法
  29. if (this._game_time >= 1) {
  30. this._game_time--;
  31. this.minu = Math.floor(this._game_time / 60) //分钟
  32. this.seco = Math.floor(this._game_time % 60) //分钟
  33. if (this.minu < 10) {
  34. this._minu = "0" + this.minu;
  35. } else {
  36. this._minu = this.minu;
  37. }
  38. if (this.seco < 10) {
  39. this._seco = "0" + this.seco;
  40. } else {
  41. this._seco = this.seco;
  42. }
  43. this.timelabel.string = this._minu + ":" + this._seco; //场景中文本框显示
  44. }
  45. },
  46. init() {
  47. this.GameMode = cc.find("GameMode").getComponent("GameMode");
  48. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  49. },
  50. });