import { _decorator, Component, easing, Node, tween, Vec2, Vec3 } from 'cc'; const { ccclass, property } = _decorator; @ccclass('MoveComponent') export class MoveComponent extends Component { @property startPos: Vec3 = new Vec3(0, 0, 0); @property endPos: Vec3 = new Vec3(0, 0, 0); @property delay: number = 0; @property moveTimer: number = 0; @property({ displayName: "线性" }) line: boolean = true; @property({ displayName: "先慢后快" }) sineIn: boolean = true; @property({ displayName: "先快后慢" }) sineOut: boolean = true; @property({ displayName: "设置为初始值" }) setToStart: boolean = false; protected onEnable(): void { console.log("触发动画z") let easeFunc = easing.linear; if (this.sineIn) { easeFunc = easing.sineIn } if (this.sineOut) { easeFunc = easing.sineOut } if (this.setToStart) { this.node.setPosition(this.startPos) } tween(this.node) .delay(this.delay) .call(() => { this.node.setPosition(this.startPos) }) .to(this.moveTimer, { position: this.endPos }, { easing: easeFunc }) .start() } }