// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class CashOutingTip extends cc.Component {

    @property(cc.Node)
    node_spotMove: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {

    }

    // update (dt) {}

    onEnable() {
        this.intervalMoveSpot();
    }

    onDisable() {
        this.cancelMoveSpot();
    }

    public interval_spotMove: number = null;
    public moveDis: number = 20;
    public curMoveNum: number = 0;
    public maxMoveNum: number = 2;

    intervalMoveSpot() {
        this.interval_spotMove = setInterval(() => {
            this.curMoveNum += 1;
            if (this.curMoveNum > this.maxMoveNum) {
                this.curMoveNum = 0;
            }
            this.node_spotMove.x = this.moveDis * (this.curMoveNum - 1);
        },200)
    }

    cancelMoveSpot() {
        if (this.interval_spotMove) {
            clearInterval(this.interval_spotMove);
            this.interval_spotMove = null;
            this.curMoveNum = 0;
            this.node_spotMove.x = -this.moveDis;
        }
    }
}
