| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // 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{
- }
- },
- });
|