TrainAni.ts 1.1 KB

123456789101112131415161718192021222324252627
  1. import { _decorator, Component, Node, tween, CCLoader, Vec3 } from 'cc';
  2. import { Utils } from '../core/utils/Utils';
  3. import { Trajectory } from '../turntable/Trajectory';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('TrainAni')
  6. export class TrainAni extends Component {
  7. public initPosition: Vec3 = Vec3.ZERO;
  8. public targetPosition: Vec3 = Vec3.ZERO;
  9. public startPosition: Vec3 = Vec3.ZERO;
  10. public endPosition: Vec3 = Vec3.ZERO;
  11. start() {
  12. this.node.setPosition(this.initPosition);
  13. tween<Node>(this.node)
  14. .to(0.8, { position: this.targetPosition }, { easing: "quadOut" })
  15. .call(() => {
  16. let trajectory = this.node.addComponent(Trajectory);
  17. trajectory.startPoint = this.startPosition;
  18. trajectory.ctrl1Point = new Vec3(Utils.random_both(300, -300), Utils.random_both(0, -500));
  19. trajectory.ctrl2Point = new Vec3(Utils.random_both(100, -100), Utils.random_both(300, -300));
  20. trajectory.endPoint = this.endPosition;
  21. })
  22. .start();
  23. }
  24. }