CanvasGroup

继承: Node2D < CanvasItem < Node < Object

将若干 2D 节点合并至单次绘制操作。

描述

Child CanvasItem nodes of a CanvasGroup are drawn as a single object. It allows to e.g. draw overlapping translucent 2D nodes without causing the overlapping sections to be more opaque than intended (set the CanvasItem.self_modulate property on the CanvasGroup to achieve this effect).

Note: The CanvasGroup uses a custom shader to read from the backbuffer to draw its children. Assigning a Material to the CanvasGroup overrides the built-in shader. To duplicate the behavior of the built-in shader in a custom Shader, use the following:

shader_type canvas_item;
render_mode unshaded;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

void fragment() {
    vec4 c = textureLod(screen_texture, SCREEN_UV, 0.0);

    if (c.a > 0.0001) {
        c.rgb /= c.a;
    }

    COLOR *= c;
}

Note: Since CanvasGroup and CanvasItem.clip_children both utilize the backbuffer, children of a CanvasGroup who have their CanvasItem.clip_children set to anything other than CanvasItem.CLIP_CHILDREN_DISABLED will not function correctly.

属性

float

clear_margin

10.0

float

fit_margin

10.0

bool

use_mipmaps

false


属性说明

float clear_margin = 10.0 🔗

  • void set_clear_margin(value: float)

  • float get_clear_margin()

设置用于扩展该 CanvasGroup 清除矩形的边距大小。会对该 CanvasGroup 所使用的后台缓冲的区域进行扩展。边距较小时可以减少后台缓冲的区域大小,从而提升性能,但如果启用了 use_mipmaps,较小的边距可能在该 CanvasGroup 边缘造成 mipmap 错误。因此,这个值应该尽量调小,但是如果画布组的边缘出现问题,就应该将其调大。


float fit_margin = 10.0 🔗

  • void set_fit_margin(value: float)

  • float get_fit_margin()

设置用于扩展该 CanvasGroup 绘图矩形的边距大小。确定该 CanvasGroup 大小的方法是:首先框定子节点的矩形区域,然后将该矩形按照 fit_margin 进行扩展。会增大该 CanvasGroup 所使用的后台缓冲的区域,也会增大该 CanvasGroup 所覆盖的面积,两者都会降低性能。这个值应该尽量调小,仅在需要时调大(例如自定义着色器效果)。


bool use_mipmaps = false 🔗

  • void set_use_mipmaps(value: bool)

  • bool is_using_mipmaps()

如果为 true,则会在绘制该 CanvasGroup 之前为其后台缓冲计算 mipmap,附加到该 CanvasGroup 的自定义 ShaderMaterial 就可以使用 mipmap。Mipmap 的生成会造成性能消耗,所以应在必要时才启用。