/** * 体力 */ import Define from "../../Tools/Define"; import GameResMgr, { uiPreName } from "../../Tools/GameResMgr"; import PlayData from "../../Tools/PlayData"; import Utils from "../../Tools/Utils"; import gameStorage from "../../Tools/gameStorage"; const {ccclass, property} = cc._decorator; @ccclass export default class TopTiLiSc extends cc.Component { @property(cc.Label) tilistr:cc.Label = null @property(cc.Label) timestr:cc.Label = null isCountDown = !1 _eneryNum = 0 public get eneryNum(){ return this._eneryNum } public set eneryNum(v:number){ console.log('更新体力值',v) this._eneryNum = v this.tilistr.string = '' + v if(v >= Define.maxEnery){ this.isCountDown = !1 this.timestr.string = '已满' }else{ this.isCountDown = !0 } } onLoad () { this.schedule(()=>{ if(this.isCountDown == !1) return PlayData.Instance.enerytime -- if(PlayData.Instance.enerytime < 0){ gameStorage.Instance.setEnergy(gameStorage.Instance.nowEnery+1) this.eneryNum = gameStorage.Instance.nowEnery PlayData.Instance.enerytime = Define.eneryTime }else{ this.timestr.string = '' + Utils.secondsFormat(PlayData.Instance.enerytime, false) } }, 1, cc.macro.REPEAT_FOREVER) this.eneryNum = gameStorage.Instance.getEnergy() } start () { } /** * 设置体力 */ setTiLi(){ this.eneryNum = gameStorage.Instance.nowEnery } /** * */ addBtnClick(){ let newnode = cc.instantiate(GameResMgr.Instance.uiPre[uiPreName.addEnery]) newnode.parent = cc.director.getScene() } update (dt) { } }