GameCanvas.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Learn cc.Class:
  2. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. settlePanel:cc.Node,
  14. },
  15. // LIFE-CYCLE CALLBACKS:
  16. // onLoad () {},
  17. start () {
  18. },
  19. gameHome(){
  20. cc.director.loadScene('BeginScene')
  21. },
  22. gameRestart(){
  23. cc.director.loadScene('GameScene')
  24. },
  25. gameOver(isWin,gameScore,gameTime){
  26. this.settlePanel.active = true
  27. if(isWin){
  28. this.settlePanel.getChildByName('TextWin').active = true
  29. this.settlePanel.getChildByName('TextFail').active = false
  30. }
  31. else{
  32. this.settlePanel.getChildByName('TextWin').active = false
  33. this.settlePanel.getChildByName('TextFail').active = true
  34. }
  35. this.settlePanel.getChildByName('GameScore').getComponent(cc.Label).string = gameScore
  36. this.settlePanel.getChildByName('GameTime').getComponent(cc.Label).string = this.secondToDate(gameTime)
  37. },
  38. secondToDate(result) {
  39. var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) : Math.floor(result / 3600);
  40. var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  41. var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  42. return result = h + ":" + m + ":" + s;
  43. },
  44. // update (dt) {},
  45. });