| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // Learn cc.Class:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
- // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
- // Learn Attribute:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
- // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
- // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
- cc.Class({
- extends: cc.Component,
- properties: {
- settlePanel:cc.Node,
- },
- // LIFE-CYCLE CALLBACKS:
- // onLoad () {},
- start () {
- },
- gameHome(){
- cc.director.loadScene('BeginScene')
- },
- gameRestart(){
- cc.director.loadScene('GameScene')
- },
- gameOver(isWin,gameScore,gameTime){
- this.settlePanel.active = true
- if(isWin){
- this.settlePanel.getChildByName('TextWin').active = true
- this.settlePanel.getChildByName('TextFail').active = false
- }
- else{
- this.settlePanel.getChildByName('TextWin').active = false
- this.settlePanel.getChildByName('TextFail').active = true
- }
- this.settlePanel.getChildByName('GameScore').getComponent(cc.Label).string = gameScore
- this.settlePanel.getChildByName('GameTime').getComponent(cc.Label).string = this.secondToDate(gameTime)
- },
- secondToDate(result) {
- var h = Math.floor(result / 3600) < 10 ? '0'+Math.floor(result / 3600) : Math.floor(result / 3600);
- var m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
- var s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
- return result = h + ":" + m + ":" + s;
- },
- // update (dt) {},
- });
|