/**
 * Created by rockyl on 2018/9/10.
 *
 * 分数标签
 */

export class ScoreLabel extends engine.Label {
    _value;
    _tmp;
	updateScore(score,animation = true) {
        this._value = score;

		if (animation && this._tmp) {
            this.animationUpdate();
		} else {
            this.updateLocal(score);
		}
    }
    
    animationUpdate(){
        let tmpInterval = setInterval(()=>{
            this._tmp += 1;
            if(this._tmp <= this._value){
                this.text  = this._tmp
            }else{
                this._tmp = this._value;
                clearInterval(tmpInterval);
            }
        },50)
    }

    updateLocal(v){
        this._tmp = v;
        this.text = v;
    }

}
