import { _decorator, Component, Vec3, tween } from 'cc'; const { ccclass, property } = _decorator; @ccclass('BezierComponent') export class BezierComponent 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); start() { tween(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.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.ctrl1Point.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; } }