| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import { _decorator, Component, Node, Vec3, tween, EventHandler } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('Trajectory')
- export class Trajectory extends Component {
- @property({ tooltip: "起点坐标", type: Vec3 })
- public startPoint: Vec3 = new Vec3(0, 0, 0);
- @property({ tooltip: "曲线控制点", type: Vec3 })
- public ctrl1Point: Vec3 = new Vec3(0, 0, 0);
- @property({ tooltip: "曲线控制点", type: Vec3 })
- public ctrl2Point: Vec3 = new Vec3(0, 0, 0);
- @property({ tooltip: "曲线终点", type: Vec3 })
- public endPoint: Vec3 = new Vec3(0, 0, 0);
- @property({ tooltip: "tween动画结束回调组件", type: EventHandler })
- public backFn: EventHandler;
- start() {
- tween<Trajectory>(this)
- .to(Math.random() * 1.2 + 0.6, { thirdOrderBeizer: 1 })
- .to(0.3, { scale: new Vec3(1.4, 1.4) })
- .to(0.3, { scale: new Vec3(1, 1) })
- .call(() => {
- this.backFn && this.backFn.emit([]);
- this.node.destroy();
- }).start();
- }
- public set thirdOrderBeizer(t: number) {
- let beizerX: number = this.startPoint.x * Math.pow((1 - t), 3) + 3 * this.ctrl1Point.x * t * Math.pow((1 - t), 2) + 3 * this.ctrl2Point.x * t * t * (1 - t) + this.endPoint.x * t * t * t;
- let beizerY: number = this.startPoint.y * Math.pow((1 - t), 3) + 3 * this.ctrl1Point.y * t * Math.pow((1 - t), 2) + 3 * this.ctrl2Point.y * t * t * (1 - t) + this.endPoint.y * t * t * t;
- this.node.position = new Vec3(beizerX, beizerY);
- }
- public get thirdOrderBeizer() {
- return 0;
- }
- public get scale(): Vec3 {
- return this.node.scale;
- }
- public set scale(value: Vec3) {
- this.node.scale = value;
- }
- }
|