import { _decorator, Component, Node, tween, CCLoader, Vec3 } from 'cc'; import { Utils } from '../core/utils/Utils'; import { Trajectory } from '../turntable/Trajectory'; const { ccclass, property } = _decorator; @ccclass('TrainAni') export class TrainAni extends Component { public initPosition: Vec3 = Vec3.ZERO; public targetPosition: Vec3 = Vec3.ZERO; public startPosition: Vec3 = Vec3.ZERO; public endPosition: Vec3 = Vec3.ZERO; start() { this.node.setPosition(this.initPosition); tween(this.node) .to(0.8, { position: this.targetPosition }, { easing: "quadOut" }) .call(() => { let trajectory = this.node.addComponent(Trajectory); trajectory.startPoint = this.startPosition; trajectory.ctrl1Point = new Vec3(Utils.random_both(300, -300), Utils.random_both(0, -500)); trajectory.ctrl2Point = new Vec3(Utils.random_both(100, -100), Utils.random_both(300, -300)); trajectory.endPoint = this.endPosition; }) .start(); } }