MaskComponent 设置 MaskComponent.Type.GRAPHICS_STENCIL 类型的遮罩没有效果,是我的用法不对吗

    let maskNode = new Node('mask');
    maskNode.addComponent(UITransformComponent)
    let mask = maskNode.addComponent(MaskComponent);
    maskNode.setAnchorPoint(0, 1)
    self.node.addChild(maskNode);
    mask.type = MaskComponent.Type.GRAPHICS_STENCIL;
    mask.graphics.roundRect(0, 0, maskNode.width, maskNode.height, 20)
    mask.graphics.fill()

然后addchild图片,显示不出来,MaskComponent.Type.ELLIPSE 和 MaskComponent.Type.RECT 是可以显示的

maskNode本身的width和hight好像没有设置哎。难道默认是0,0?

设置了也不行,我是设置了的,这里例子代码删掉了

我看了源代码,感觉有点不合理,很多地方会调用下面这个updateGraphics,比如设置masktype,或者onenable或者图形内容重塑onRestore。然而,调用这个函数之后,graphic就被清除了,但是GRAPHICS_STENCIL类型这里没有任何代码,所以要保证自定义graphics是在mask的最后初始化好之后再写,不然很容易被clear掉

protected _updateGraphics () {
    if (!this._graphics) {
        return;
    }
    const node = this.node;
    const graphics = this._graphics;
    // Share render data with graphics content
    graphics.clear();
    const size = node.getContentSize();
    const width = size.width;
    const height = size.height;
    const ap = node.getAnchorPoint();
    const x = -width * ap.x;
    const y = -height * ap.y;
    if (this._type === MaskType.RECT) {
        graphics.rect(x, y, width, height);
    } else if (this._type === MaskType.ELLIPSE) {
        const center = new Vec3(x + width / 2, y + height / 2, 0);
        const radius = new Vec3(width / 2, height / 2, 0,
        );
        const points = _calculateCircle(center, radius, this._segments);
        for (let i = 0; i < points.length; ++i) {
            const point = points[i];
            if (i === 0) {
                graphics.moveTo(point.x, point.y);
            } else {
                graphics.lineTo(point.x, point.y);
            }
        }
        graphics.close();
    }

    graphics.fill();
}

感谢四楼反馈,现在的设计可能是有一些情况没有考虑到,clear 操作应该要加判断。

这里建议用 graphics 组件绘制一个相同图形,看下位置对不对

ui中同时存在多个mask 裁切会有一部分跑到另一个mask中显示,是什么问题

能看看我的贴子问题不

这引擎到现在mask仍然有问题 :rofl: