creator3.8 如何贝塞尔画虚线是不是不支持!!!!

creator3.8 如何贝塞尔画虚线是不是不支持!!!!creator3.8 如何贝塞尔画虚线是不是不支持!!!!creator3.8 如何贝塞尔画虚线是不是不支持!!!!creator3.8 如何贝塞尔画虚线是不是不支持!!!!creator3.8 如何贝塞尔画虚线是不是不支持!!!!


简单写了一个

代码帖给你

import { _decorator, Component, Graphics, Node, Vec2, Vec3 } from ‘cc’;

const { ccclass, property } = _decorator;

@ccclass(‘main’)

export class main extends Component {

@property(Node)

starNode: Node = null!;

@property(Node)

endNode: Node = null!;

@property(Node)

c1Node: Node = null!;

@property(Node)

c2Node: Node = null!;

@property(Graphics)

graphics: Graphics = null!;

start() {

    // 每隔0.05获取一个点

    let t = 0;

    let points = [];

    while (t <= 1) {

        let point = this.bezier3(this.starNode.position, this.endNode.position, this.c1Node.position, this.c2Node.position, t);

        points.push(point);

        t += 0.02;

    }

    // 绘制曲线

    this.graphics.strokeColor.fromHEX('#ff0000');

    this.graphics.lineWidth = 5;

    for (let i = 0; i < points.length; i+=2) {

        if(i + 1 >= points.length) {

            break;

        }

        this.graphics.moveTo(points[i].x, points[i].y);

        this.graphics.lineTo(points[i+1].x, points[i+1].y);

    }

    this.graphics.stroke();

}

// 3次贝塞尔曲线

bezier3(start:Vec3, c1:Vec3, c2:Vec3, end:Vec3, t:number) {

    let x = start.x * Math.pow(1 - t, 3) + 3 * c1.x * t * Math.pow(1 - t, 2) + 3 * c2.x * Math.pow(t, 2) * (1 - t) + end.x * Math.pow(t, 3);

    let y = start.y * Math.pow(1 - t, 3) + 3 * c1.y * t * Math.pow(1 - t, 2) + 3 * c2.y * Math.pow(t, 2) * (1 - t) + end.y * Math.pow(t, 3);

    return new Vec2(x, y);

}

// 2次贝塞尔曲线

bezier2(start:Vec3, c:Vec3, end:Vec3, t:number) {

    let x = start.x * Math.pow(1 - t, 2) + 2 * c.x * t * (1 - t) + end.x * Math.pow(t, 2);

    let y = start.y * Math.pow(1 - t, 2) + 2 * c.y * t * (1 - t) + end.y * Math.pow(t, 2);

    return new Vec2(x, y);

}

update(deltaTime: number) {

   

}

}

1赞

多谢,再次经过处理可以实现功能了 :100: :+1: