// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { index: { default: 0, type:cc.Integer, } // foo: { // // ATTRIBUTES: // default: null, // The default value will be used only when the component attaching // // to a node for the first time // type: cc.SpriteFrame, // optional, default is typeof default // serializable: true, // optional, default is true // }, // bar: { // get () { // return this._bar; // }, // set (value) { // this._bar = value; // } // }, }, // LIFE-CYCLE CALLBACKS: onLoad () { this._init() }, start () { }, _init(){ lifes[this.index] = this this.life = this.getComponent(cc.ProgressBar); this.Defend = UtilsNode.getNode("Defend",this.node) //防御值 this.Defendlife = this.Defend.getComponent(cc.ProgressBar); this.initLife() }, //初始化 血量 和防御值 initLife(){ this.life.progress = 1 this.Defendlife.progress = 1 }, getLife(){ // Log.info("现在得到的是",this.life.totalLength); // Log.info("现在得到的是",this.life.progress); return this.life.progress*100 }, // addLife(num,callback){ // Log.info("现在得到的是",this.life.totalLength); // Log.info("现在得到的是",this.life.progress); var temp = this.life.progress*100+num this.life.progress= (this.life.progress*100+num)/100 if (temp <= 0) { if (callback) { callback(this.index); return } }else{ } }, addDefendLife(num,callback){ // Log.info("现在得到的是",this.life.totalLength); // Log.info("现在得到的是",this.life.progress); var temp = this.Defendlife.progress*100+num this.Defendlife.progress= (this.Defendlife.progress*100+num)/100 if (temp <= 0) { if (callback) { callback(this.index); this.Defendlife.progress = 1 return } }else{ } }, update (dt) { if (!gameManager.getGameType()) { if (this.Defendlife) { if (this.Defendlife.progress*100<100) { this.Defendlife.progress+=0.0005 }else{ this.Defendlife.progress = 1 } } }else{ } }, });