要不是试试graphics
static drawRect(node: Node, rect: Rect, color: Color = Color.RED) {
let newNode = new Node();
newNode.addComponent(UITransform).contentSize = node.getComponent(UITransform).contentSize;
node.addChild(newNode);
let graphics = newNode.addComponent(Graphics)
graphics.strokeColor = color;
graphics.lineWidth = 2;
//获取在本地坐标系的位置
let worldPos = node.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO);
rect.x = rect.x - worldPos.x;
rect.y = rect.y - worldPos.y;
graphics.moveTo(rect.x, rect.y);
graphics.lineTo(rect.x + rect.width, rect.y);
graphics.moveTo(rect.x + rect.width, rect.y);
graphics.lineTo(rect.x + rect.width, rect.y + rect.height);
graphics.moveTo(rect.x + rect.width, rect.y + rect.height);
graphics.lineTo(rect.x, rect.y + rect.height);
graphics.moveTo(rect.x, rect.y + rect.height);
graphics.lineTo(rect.x, rect.y);
graphics.stroke();
}








