原文是绘制固定虚线
因为Graphics好像是 每次都会重绘,所以可能会比较耗性能
自己取舍
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
content: cc.Node = null;
@property(cc.Node)
cNode: cc.Node = null;
@property(cc.Graphics)
GraphicsNode: cc.Graphics = null; //Graphics 绘制组件
@property(cc.Node)
colorNode: cc.Node = null; //颜色节点
linePosArr: any[]; //存放起始坐标和目标坐标
isUpdate: boolean = true; //是否开启update
@property(cc.Node)
btnNode: cc.Node = null; //按钮
maxMoveNum = 30; //最大偏移
moveNum = 1; //偏移
dtNum: number = 1;//dt记数
start() {
this.initNode()
this.btnNode.on('click', () => {
this.moveLine();
})
}
moveLine() {
this.GraphicsNode.clear();
this.moveNum++;
if (this.moveNum > this.maxMoveNum) {
this.moveNum = 0;
}
this.GraphicsNode.clear();
let arr = this.linePosArr
for (let i = 0; i < arr.length; i++) {
let item = arr[i]
this.drawLineOfDashes(this.GraphicsNode, item.fromPos, item.toPos, item.color)