MoveAction.ts 965 Bytes

const { ccclass, property } = cc._decorator;

@ccclass
export default class MoveAction extends cc.Component {

    @property
    speed: number = 1;
    @property
    srcPosX: number = 0;
    @property
    srcPosY: number = 0;
    @property
    tempPosX: number = 0;
    @property
    tempPosY: number = 0;

    private readonly _baseTime: number = 1;

    onLoad() { }

    start() {

    }

    onEnable() {
        let actTime: number = this._baseTime / this.speed;
        let ease = cc.easeSineInOut();
        let tempAct = cc.moveTo(actTime, cc.v2(this.tempPosX, this.tempPosY)).easing(ease);
        let srcAct = cc.moveTo(actTime, cc.v2(this.srcPosX, this.srcPosY)).easing(ease);
        this.node.stopAllActions();
        this.node.runAction(cc.repeatForever(cc.sequence(tempAct, srcAct)));
    }

    onDisable() {
        this.node.stopAllActions();
        this.node.x = this.srcPosX;
        this.node.y = this.srcPosY;
    }



    update(dt) { }
}