就想显示个矩形。。。折腾一晚上了怎么都不显示
感谢回复。刚按照例子里的方法在场景中直接拖Graphics绑定代码组件,是可以显示的。用代码创建就不显示,我的代码是这样子的:
const modal = new Node(‘modal’);
const g = modal.addComponent(Graphics);
g.clear();
g.lineWidth = 10;
g.fillColor.fromHEX(’#ff0000’);
g.rect(0, 0, 800, 1000);
g.stroke();
g.fill();
return modal;
是我少设置了什么嘛?
打印出来父节点和modal自身的active和activeInHierarchy都是true。
model 的 parent 是谁?
结构是打算做成这样:所有的界面都有一个根节点,显示Panel的时候如果是modal就创建一个modal背景在panel的后面。
所以modal的父级和panel的父级一样,现在是panel通过prefab加载创建出来正常显示。modal不显示。
show的代码是这样:
async show(container?: Node, modal?: boolean) {
await this.load();
if (container) {
this._container = container;
}
if (!this._container) {
this._container = UILayer.inst.getPanelLayer();
}
this._container.on(Node.EventType.SIZE_CHANGED, this.onParentSizeChange, this);
if (modal) {
if (!this._modalNode) {
this._modalNode = this.createModal();
} else {
this._modalNode.active = true;
}
this._container.addChild(this._modalNode);
}
this.doShow();
const t = this.getShowTween();
t && t.start();
}
我这里建议你直接用绘制逻辑测试绘制成不成功,然后 graphics 是不是在 canvas 下
好的,感谢,我先试试。
终于试出来了。需要先把modal的Node添加到舞台,再绘制才可以。
是不是Graphics在添加到节点上的时候有清除的动作。
不是,是还没进行初始化,导致你的绘制指令都被 return 了,这个应该要做一些优化
设置了下layer就显示了。graphicsNode1.layer = Layers.Enum.UI_2D;

太感谢小红书上这位兄弟了。
https://www.jianshu.com/p/e8573dbaebed

也感谢CSDN的这位兄弟。

