Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

CanvasItem

繼承: Node < Object

被繼承: Control, Node2D

2D 空間中所有物件的抽象基底類別。

說明

2D 空間中所有物件的抽象基底類別。畫布項目以樹狀排列;子節點繼承並擴充其父節點的變換。CanvasItem 由 Control 擴充為 GUI 相關的節點,由 Node2D 擴充為 2D 遊戲物件。

任何 CanvasItem 都可以進行繪圖。繪圖時,引擎會呼叫 queue_redraw(),然後 NOTIFICATION_DRAW 就會在空閒時被接收到以請求重繪。因此,畫布項目不需要每一影格都重繪,這顯著提升了效能。這個類還提供了幾個用於在 CanvasItem 上繪圖的函式(見 draw_* 函式)。不過這些函式都只能在 _draw() 及其對應的 Object._notification() 或連接到 draw 的方法內使用。

畫布項目在其畫布層上是按樹狀順序繪製的。預設情況下,子項目位於其父項目的上方,因此根 CanvasItem 將被畫在所有項目的後面。這種行為可以針對每個畫布項目進行更改。

CanvasItem 可以隱藏,隱藏時也會隱藏其子項目。通過調整 CanvasItem 的各種其它屬性,你還可以調制它的顏色(通過 modulate 或 self_modulate)、更改 Z 索引、混合模式等。

請注意,變換、調制、可見性等屬性只會傳播至直屬的 CanvasItem 子節點。如果中間有 Node、AnimationPlayer 等非 CanvasItem 節點,那麼更深層 CanvasItem 的位置和 modulate 鏈就是獨立的了。另見 top_level。

教學

屬性

ClipChildrenMode

clip_children

0

int

light_mask

1

Material

material

Color

modulate

Color(1, 1, 1, 1)

OversamplingWithScale

oversampling_with_scale

0

Color

self_modulate

Color(1, 1, 1, 1)

bool

show_behind_parent

false

TextureFilter

texture_filter

0

TextureRepeat

texture_repeat

0

bool

top_level

false

bool

use_parent_material

false

int

visibility_layer

1

bool

visible

true

bool

y_sort_enabled

false

bool

z_as_relative

true

int

z_index

0

方法

void

_draw() virtual

void

draw_animation_slice(animation_length: float, slice_begin: float, slice_end: float, offset: float = 0.0)

void

draw_arc(center: Vector2, radius: float, start_angle: float, end_angle: float, point_count: int, color: Color, width: float = -1.0, antialiased: bool = false)

void

draw_char(font: Font, pos: Vector2, char: String, font_size: int = 16, modulate: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_char_outline(font: Font, pos: Vector2, char: String, font_size: int = 16, size: int = -1, modulate: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const

void

draw_circle(position: Vector2, radius: float, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false)

void

draw_colored_polygon(points: PackedVector2Array, color: Color, uvs: PackedVector2Array = PackedVector2Array(), texture: Texture2D = null)

void

draw_dashed_line(from: Vector2, to: Vector2, color: Color, width: float = -1.0, dash: float = 2.0, aligned: bool = true, antialiased: bool = false)

void

draw_ellipse(position: Vector2, major: float, minor: float, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false)

void

draw_ellipse_arc(center: Vector2, major: float, minor: float, start_angle: float, end_angle: float, point_count: int, color: Color, width: float = -1.0, antialiased: bool = false)

void

draw_end_animation()

void

draw_lcd_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1))

void

draw_line(from: Vector2, to: Vector2, color: Color, width: float = -1.0, antialiased: bool = false)

void

draw_mesh(mesh: Mesh, texture: Texture2D, transform: Transform2D = Transform2D(1, 0, 0, 1, 0, 0), modulate: Color = Color(1, 1, 1, 1))

void

draw_msdf_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), outline: float = 0.0, pixel_range: float = 4.0, scale: float = 1.0)

void

draw_multiline(points: PackedVector2Array, color: Color, width: float = -1.0, antialiased: bool = false)

void

draw_multiline_colors(points: PackedVector2Array, colors: PackedColorArray, width: float = -1.0, antialiased: bool = false)

void

draw_multiline_string(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, max_lines: int = -1, modulate: Color = Color(1, 1, 1, 1), brk_flags: BitField[LineBreakFlag] = 3, justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const

void

draw_multiline_string_outline(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, max_lines: int = -1, size: int = 1, modulate: Color = Color(1, 1, 1, 1), brk_flags: BitField[LineBreakFlag] = 3, justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const

void

draw_multimesh(multimesh: MultiMesh, texture: Texture2D)

void

draw_polygon(points: PackedVector2Array, colors: PackedColorArray, uvs: PackedVector2Array = PackedVector2Array(), texture: Texture2D = null)

void

draw_polyline(points: PackedVector2Array, color: Color, width: float = -1.0, antialiased: bool = false)

void

draw_polyline_colors(points: PackedVector2Array, colors: PackedColorArray, width: float = -1.0, antialiased: bool = false)

void

draw_primitive(points: PackedVector2Array, colors: PackedColorArray, uvs: PackedVector2Array, texture: Texture2D = null)

void

draw_rect(rect: Rect2, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false)

void

draw_set_transform(position: Vector2, rotation: float = 0.0, scale: Vector2 = Vector2(1, 1))

void

draw_set_transform_matrix(xform: Transform2D)

void

draw_string(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, modulate: Color = Color(1, 1, 1, 1), justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const

void

draw_string_outline(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, size: int = 1, modulate: Color = Color(1, 1, 1, 1), justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const

void

draw_style_box(style_box: StyleBox, rect: Rect2)

void

draw_texture(texture: Texture2D, position: Vector2, modulate: Color = Color(1, 1, 1, 1))

void

draw_texture_rect(texture: Texture2D, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false)

void

draw_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true)

void

force_update_transform()

RID

get_canvas() const

RID

get_canvas_item() const

CanvasLayer

get_canvas_layer_node() const

Transform2D

get_canvas_transform() const

Vector2

get_global_mouse_position() const

Transform2D

get_global_transform() const

Transform2D

get_global_transform_with_canvas() const

Variant

get_instance_shader_parameter(name: StringName) const

Vector2

get_local_mouse_position() const

Transform2D

get_screen_transform() const

Transform2D

get_transform() const

Rect2

get_viewport_rect() const

Transform2D

get_viewport_transform() const

bool

get_visibility_layer_bit(layer: int) const

World2D

get_world_2d() const

void

hide()

bool

is_local_transform_notification_enabled() const

bool

is_transform_notification_enabled() const

bool

is_visible_in_tree() const

Vector2

make_canvas_position_local(viewport_point: Vector2) const

InputEvent

make_input_local(event: InputEvent) const

void

move_to_front()

void

queue_redraw()

void

set_instance_shader_parameter(name: StringName, value: Variant)

void

set_notify_local_transform(enable: bool)

void

set_notify_transform(enable: bool)

void

set_visibility_layer_bit(layer: int, enabled: bool)

void

show()


訊號

draw() 🔗

當該 CanvasItem 必須重繪時發出,發生在相關的 NOTIFICATION_DRAW 通知之後,呼叫 _draw() 之前。

注意:延遲連接無法使用 draw_* 方法進行繪製。


hidden() 🔗

當該節點隱藏時發出,即不再在樹中可見(見 is_visible_in_tree())。


item_rect_changed() 🔗

當 CanvasItem 的邊界(位置或大小)發生變化,或者發生可能影響這些邊界的操作(例如更改 Sprite2D.texture)時發出。


visibility_changed() 🔗

在 CanvasItem 的可見性改變時發射,這種改變或是因為其自身的 visible 屬性發生了變化,或是因為其在樹中的可見性發生了變化(見 is_visible_in_tree())。

該訊號在相關的 NOTIFICATION_VISIBILITY_CHANGED 通知之後發出。


列舉

enum TextureFilter: 🔗

TextureFilter TEXTURE_FILTER_PARENT_NODE = 0

該 CanvasItem 將從其父級繼承篩檢程式。

TextureFilter TEXTURE_FILTER_NEAREST = 1

紋理僅取最鄰近像素,近看呈現馬賽克,遠處因未取樣 mipmap 而顯得顆粒。

TextureFilter TEXTURE_FILTER_LINEAR = 2

紋理在最鄰近 4 像素間插值,近看平滑,遠處因未取樣 mipmap 仍顆粒。

TextureFilter TEXTURE_FILTER_NEAREST_WITH_MIPMAPS = 3

紋理過濾從最近的像素讀取並在最近的 2 個多級漸遠紋理之間進行混合(或者如果 ProjectSettings.rendering/textures/default_filters/use_nearest_mipmap_filter 為 true,則使用最近的多級漸遠紋理)。這使得紋理從近處看起來像素化,從遠處看起來平滑。

將此用於可能以低縮放查看的非像素藝術紋理(例如,由於 Camera2D 縮放或精靈縮放),因為多級漸遠紋理對於平滑小於螢幕像素的像素很重要。

TextureFilter TEXTURE_FILTER_LINEAR_WITH_MIPMAPS = 4

紋理過濾在最近的 4 個像素和最近的 2 個多級漸遠紋理之間進行混合(或者如果 ProjectSettings.rendering/textures/default_filters/use_nearest_mipmap_filter 為 true,則使用最近的多級漸遠紋理)。這使得紋理從近處看起來平滑,從遠處看起來也平滑。

將此用於可能以低縮放查看的非像素藝術紋理(例如,由於 Camera2D 縮放或精靈縮放),因為多級漸遠紋理對於平滑小於螢幕像素的像素很重要。

TextureFilter TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC = 5

紋理過濾從最近的像素讀取並根據表面和相機檢視之間的角度在 2 個多級漸遠紋理之間進行混合(或者如果 ProjectSettings.rendering/textures/default_filters/use_nearest_mipmap_filter 為 true,則使用最近的多級漸遠紋理)。這使得紋理從近處看起來像素化,從遠處看起來平滑。各向異性過濾提高了幾乎與相機位於一條線的表面上的紋理品質,但速度稍慢。各向異性過濾層級可以通過調整 ProjectSettings.rendering/textures/default_filters/anisotropic_filtering_level 來改變。

注意:該紋理過濾在 2D 專案中很少有用。TEXTURE_FILTER_NEAREST_WITH_MIPMAPS 在這種情況下通常更合適。

TextureFilter TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC = 6

紋理過濾在最近的 4 個像素之間進行混合,並基於表面與相機檢視之間的角度在 2 個多級漸遠紋理之間進行混合(或者如果 ProjectSettings.rendering/textures/default_filters/use_nearest_mipmap_filter 為 true,則使用最近的多級漸遠紋理)。這使得紋理從近處看起來平滑,從遠處看起來也平滑。各向異性過濾提高了幾乎與相機位於一條線的表面上的紋理品質,但速度稍慢。各向異性過濾層級可以通過調整 ProjectSettings.rendering/textures/default_filters/anisotropic_filtering_level 來改變。

注意:該紋理過濾在 2D 專案中很少有用。TEXTURE_FILTER_LINEAR_WITH_MIPMAPS 在這種情況下通常更合適。

TextureFilter TEXTURE_FILTER_MAX = 7

代表 TextureFilter 列舉的大小。


enum TextureRepeat: 🔗

TextureRepeat TEXTURE_REPEAT_PARENT_NODE = 0

該 CanvasItem 將從其父級繼承重複模式。

TextureRepeat TEXTURE_REPEAT_DISABLED = 1

紋理不會重複。在紋理範圍之外取樣會導致邊緣像素“拉伸”。你可以通過確保在紋理兩側各有一個 1 像素的完全透明邊框來避免這種情況。

TextureRepeat TEXTURE_REPEAT_ENABLED = 2

紋理會在超出紋理大小後重複。

TextureRepeat TEXTURE_REPEAT_MIRROR = 3

紋理會在超出紋理大小後以“2×2 平鋪模式”重複。偶數位置的重複紋理會被鏡像。

TextureRepeat TEXTURE_REPEAT_MAX = 4

代表 TextureRepeat 列舉的大小。


enum ClipChildrenMode: 🔗

ClipChildrenMode CLIP_CHILDREN_DISABLED = 0

子節點繪製在該節點之上,不會被裁剪。

ClipChildrenMode CLIP_CHILDREN_ONLY = 1

該節點用作遮罩,不進行繪製。遮罩基於該節點的 Alpha 通道:保留不透明像素,丟棄透明像素,半透明像素根據不透明度混合。子節點受到該節點繪製區域的裁剪。

ClipChildrenMode CLIP_CHILDREN_AND_DRAW = 2

該節點用作遮罩,也會進行繪製。遮罩基於該節點的 Alpha 通道:保留不透明像素,丟棄透明像素,半透明像素根據不透明度混合。子節點受到該節點繪製區域的裁剪。

ClipChildrenMode CLIP_CHILDREN_MAX = 3

代表 ClipChildrenMode 列舉的大小。


enum OversamplingWithScale: 🔗

OversamplingWithScale OVERSAMPLING_WITH_SCALE_PARENT_NODE = 0

該 CanvasItem(2D 畫布項)將繼承其父節點的過取樣模式。

OversamplingWithScale OVERSAMPLING_WITH_SCALE_DISABLED = 1

過取樣不受 CanvasItem(2D 畫布項)縮放比例的影響,並且與 Viewport(視埠)的過取樣設定保持一致。

OversamplingWithScale OVERSAMPLING_WITH_SCALE_ENABLED = 2

過取樣率是 CanvasItem(2D 畫布項)的縮放比例與 Viewport(視埠)過取樣設定的乘積。

OversamplingWithScale OVERSAMPLING_WITH_SCALE_MAX = 3

表示 OversamplingWithScale(帶縮放比例的過取樣)列舉的大小。


常數

NOTIFICATION_TRANSFORM_CHANGED = 2000 🔗

is_transform_notification_enabled() 為 true 時,節點的全域變換發生改變時收到的通知。另見 set_notify_transform() 和 get_transform()。

注意:Camera2D、CollisionObject2D 等許多畫布項會自動啟用此功能以確保正常執行。

NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 35 🔗

is_local_transform_notification_enabled() 為 true 時,節點的變換發生改變時收到的通知。父級 Node2D 的變換發生改變時不會收到該通知。另見 set_notify_local_transform()。

注意:Camera2D、CollisionShape2D 等許多畫布項會自動啟用此功能以確保正常執行。

NOTIFICATION_DRAW = 30 🔗

要求繪製該 CanvasItem(見 _draw())。

NOTIFICATION_VISIBILITY_CHANGED = 31 🔗

節點的可見性發生改變時收到的通知(見 visible 和 is_visible_in_tree())。

該通知會在相關 visibility_changed 訊號之前收到。

NOTIFICATION_ENTER_CANVAS = 32 🔗

該 CanvasItem 已進入畫布。

NOTIFICATION_EXIT_CANVAS = 33 🔗

該 CanvasItem 已退出畫布。

該通知會以反向順序發送。

NOTIFICATION_WORLD_2D_CHANGED = 36 🔗

該 CanvasItem 注冊至新的 World2D 時收到的通知(見 get_world_2d())。


屬性說明

ClipChildrenMode clip_children = 0 🔗

該節點作為遮罩對子節點進行裁剪的模式。

注意:裁剪的節點無法巢狀,也不能位於 CanvasGroup 中。如果該節點的祖先節點裁剪了它的子級,或者祖先節點是 CanvasGroup,那麼這個節點的裁剪模式應當設為 CLIP_CHILDREN_DISABLED,從而避免意外行為。


int light_mask = 1 🔗

  • void set_light_mask(value: int)

  • int get_light_mask()

該 CanvasItem 的渲染層,用於回應 Light2D 節點。


Material material 🔗

套用於這個 CanvasItem 的材質。


Color modulate = Color(1, 1, 1, 1) 🔗

  • void set_modulate(value: Color)

  • Color get_modulate()

套用於這個 CanvasItem 的顏色。這個屬性會影響子級 CanvasItem,與只會影響節點自身的 self_modulate 不同。


OversamplingWithScale oversampling_with_scale = 0 🔗

If enabled, oversampling for this CanvasItem is automatically adjusted with scale. This makes fonts and DPITexture images automatically re-render to match the actual scale they are drawn at, for crisper visuals. This has a performance impact on the CPU every time the node's scale changes, so it is disabled by default.

Note: For Control nodes with Control.offset_transform_enabled set to true, scale-based oversampling is only effective if Control.offset_transform_visual_only is false. This ensures there is no performance overhead when using visual-only offset transforms (as often used in animations).


Color self_modulate = Color(1, 1, 1, 1) 🔗

  • void set_self_modulate(value: Color)

  • Color get_self_modulate()

套用至這個 CanvasItem 的顏色。這個屬性不會影響子級 CanvasItem,與會同時影響節點自身和子級的 modulate 不同。

注意:內部子節點也不受這個屬性的影響(見 Node.add_child() 方法的 include_internal 參數)。內建節點的內部子節點包括 ColorPicker 中的滑塊、TabContainer 中的分頁欄等。


bool show_behind_parent = false 🔗

  • void set_draw_behind_parent(value: bool)

  • bool is_draw_behind_parent_enabled()

如果為 true,則該節點繪製在其父節點後面。


TextureFilter texture_filter = 0 🔗

渲染該 CanvasItem 的紋理時使用的過濾模式。


TextureRepeat texture_repeat = 0 🔗

用於渲染該 CanvasItem 紋理的重複模式。它會影響在紋理範圍之外取樣時發生的情況,例如,設定比紋理大的 Sprite2D.region_rect 或在紋理外部分配 Polygon2D UV 點。

注意:TextureRect 不受 texture_repeat 的影響,因為它使用自己的紋理重複實作。


bool top_level = false 🔗

  • void set_as_top_level(value: bool)

  • bool is_set_as_top_level()

如果為 true,則該 CanvasItem 不會繼承父級 CanvasItem 的變換。它的繪製順序也會發生改變,會在其他沒有將 top_level 設定為 true 的 CanvasItem 之上繪製。效果和把該 CanvasItem 作為裸 Node 的子級一樣。


bool use_parent_material = false 🔗

  • void set_use_parent_material(value: bool)

  • bool get_use_parent_material()

如果為 true,則將父級 CanvasItem 的 material 屬性用作該節點的材質。


int visibility_layer = 1 🔗

  • void set_visibility_layer(value: int)

  • int get_visibility_layer()

The rendering layer in which this CanvasItem is rendered by Viewport nodes. A Viewport will render a CanvasItem if it and all its parents share a layer with the Viewport's canvas cull mask. For an easier way to change this value from a script, see set_visibility_layer_bit().

Note: A CanvasItem does not inherit its parents' visibility layers. This means that if a parent CanvasItem does not have all the same layers as its child, the child may not be visible even if both the parent and child have visible set to true. For example, if a parent has layer 1 and a child has layer 2, the child will not be visible in a Viewport with the canvas cull mask set to layer 1 or 2 (see Viewport.canvas_cull_mask). To ensure that both the parent and child are visible, the parent must have both layers 1 and 2, or the child must have top_level set to true.


bool visible = true 🔗

  • void set_visible(value: bool)

  • bool is_visible()

如果為 true,則允許繪製該 CanvasItem。實際是否對該 CanvasItem 進行繪製取決於該節點的所有 CanvasItem 祖級節點的可見性。換句話說:該 CanvasItem 只有在 is_visible_in_tree() 回傳 true,並且所有 CanvasItem 祖級節點都至少與這個 CanvasItem 共享一個 visibility_layer。

注意:對於繼承了 Popup 的控制項,使其可見的正確方法是呼叫多個 popup*() 函式之一。


bool y_sort_enabled = false 🔗

  • void set_y_sort_enabled(value: bool)

  • bool is_y_sort_enabled()

If true, this and child CanvasItem nodes with a higher Y position are rendered in front of nodes with a lower Y position. If false, this and child CanvasItem nodes are rendered normally in scene tree order.

With Y-sorting enabled on a parent node ('A') but disabled on a child node ('B'), the child node ('B') is sorted but its children ('C1', 'C2', etc.) render together on the same Y position as the child node ('B'). This allows you to organize the render order of a scene without changing the scene tree.

Nodes sort relative to each other only if they are on the same z_index.

Note: Y-sorting does not affect the order in which CanvasItem nodes are processed, or the way input events are handled. This is especially important to keep in mind for Control nodes.


bool z_as_relative = true 🔗

  • void set_z_as_relative(value: bool)

  • bool is_z_relative()

如果為 true,則該節點的最終 Z 索引是相對於父節點的 Z 索引而言的。

例如 z_index 為 2、父節點的最終 Z 索引為 3,那麼該節點的最終 Z 索引就是 5(2 + 3)。


int z_index = 0 🔗

  • void set_z_index(value: int)

  • int get_z_index()

The order in which this node is drawn. A node with a higher Z index will display in front of others. Must be between RenderingServer.CANVAS_ITEM_Z_MIN and RenderingServer.CANVAS_ITEM_Z_MAX (inclusive).

Note: The Z index does not affect the order in which CanvasItem nodes are processed, or the way input events are handled. This is especially important to keep in mind for Control nodes.


方法說明

void _draw() virtual 🔗

當 CanvasItem 被請求重繪時呼叫(手動呼叫或者引擎呼叫 queue_redraw() 之後)。

對應於 Object._notification() 中的 NOTIFICATION_DRAW 通知。


void draw_animation_slice(animation_length: float, slice_begin: float, slice_end: float, offset: float = 0.0) 🔗

後續的繪製命令將被忽略,除非它們位於指定的動畫切片內。這是實作在背景上迴圈而不是不斷重繪的動畫的更快方法。


void draw_arc(center: Vector2, radius: float, start_angle: float, end_angle: float, point_count: int, color: Color, width: float = -1.0, antialiased: bool = false) 🔗

使用一個 uniform color 和 width 以及可選的反鋸齒(僅支援正 width ),在給定的角度之間繪製一條未填充的弧線。point_count 的值越大,該曲線越平滑。center 定義在區域空間。繪製橢圓弧見 draw_ellipse_arc()。另見 draw_circle()。

如果 width 為負,則它將被忽略,並使用 RenderingServer.PRIMITIVE_LINE_STRIP 繪製該弧線。這意味著當縮放 CanvasItem 時,弧線將保持細長。如果不需要此行為,請傳遞一個正的 width,如 1.0。

如果 start_angle < end_angle ,則弧線是從 start_angle 朝向 end_angle 的值繪製的,即是順時針方向;否則為逆時針方向。以相反的順序傳遞相同的角度,將產生相同的弧線。如果 start_angle 和 end_angle 的差的絕對值大於 @GDScript.TAU 弧度,則繪製一個完整的圓弧(即弧線不會與自身重疊)。


void draw_char(font: Font, pos: Vector2, char: String, font_size: int = 16, modulate: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

使用自訂字型繪製字串中的第一個字元。如果 oversampling 大於零則會用作字型過取樣係數,否則使用視埠的過取樣設定。pos 定義在區域空間。


void draw_char_outline(font: Font, pos: Vector2, char: String, font_size: int = 16, size: int = -1, modulate: Color = Color(1, 1, 1, 1), oversampling: float = 0.0) const 🔗

使用自訂字型繪製字串中第一個字元的輪廓。如果 oversampling 大於零則會用作字型過取樣係數,否則使用視埠的過取樣設定。pos 定義在區域空間。


void draw_circle(position: Vector2, radius: float, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false) 🔗

Draws a circle, with position defined in local space. See also draw_ellipse(), draw_arc(), draw_polyline(), and draw_polygon().

If filled is true, the circle will be filled with the color specified. If filled is false, the circle will be drawn as a stroke with the color and width specified.

If width is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

If antialiased is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.

Note: width is only effective if filled is false.


void draw_colored_polygon(points: PackedVector2Array, color: Color, uvs: PackedVector2Array = PackedVector2Array(), texture: Texture2D = null) 🔗

繪製一個由任意數量的點構成的實心多邊形,凹凸均可。points 陣列中的點定義在區域空間。與 draw_polygon() 不同,必須為整個多邊形制定單一顏色。

注意:如果你需要頻繁重繪同樣的多邊形,包含大量頂點,請考慮預先使用 Geometry2D.triangulate_polygon() 進行三角剖分計算,並使用 draw_mesh()、draw_multimesh() 或 RenderingServer.canvas_item_add_triangle_array()。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_dashed_line(from: Vector2, to: Vector2, color: Color, width: float = -1.0, dash: float = 2.0, aligned: bool = true, antialiased: bool = false) 🔗

Draws a dashed line from a 2D point to another, with a given color and width. The from and to positions are defined in local space. See also draw_line(), draw_multiline(), and draw_polyline().

If width is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the line parts will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

dash is the length of each dash in pixels, with the gap between each dash being the same length. If aligned is true, the length of the first and last dashes may be shortened or lengthened to allow the line to begin and end at the precise points defined by from and to. Both ends are always symmetrical when aligned is true. If aligned is false, all dashes will have the same length, but the line may appear incomplete at the end due to the dash length not dividing evenly into the line length. Only full dashes are drawn when aligned is false.

If antialiased is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.

Note: antialiased is only effective if width is greater than 0.0.


void draw_ellipse(position: Vector2, major: float, minor: float, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false) 🔗

繪製一個長半軸長 major 、短半軸長 minor 的橢圓。另見 draw_circle()、draw_ellipse_arc()、draw_polyline() 和 draw_polygon()。

如果 filled 為 true,則圓形將使用指定的 color 填充。如果 filled 為 false,則圓形將被繪製為具有指定的 color 和 width 的筆划。

如果 width 為負,則將繪製兩點圖元而不是四點圖元。這意味著當縮放 CanvasItem 時,線條將保持細長。如果不需要此行為,請傳遞一個正的 width,如 1.0。

如果 antialiased 為 true,則半透明的“羽毛”將附加到邊界,使輪廓變得平滑。

注意:width 只有在 filled 為 false 時才有效。


void draw_ellipse_arc(center: Vector2, major: float, minor: float, start_angle: float, end_angle: float, point_count: int, color: Color, width: float = -1.0, antialiased: bool = false) 🔗

在指定角度之間,以一致的 color 和 width 繪製未填滿的橢圓弧。可選擇啟用反鋸齒(僅支援正的 width)。point_count 越大,曲線越平滑。繪製圓弧請參閱 draw_arc();另請參閱 draw_ellipse()。

若 width 為負值,就會忽略該值,改用 RenderingServer.PRIMITIVE_LINE_STRIP 繪製弧線。這表示 CanvasItem 縮放時,弧線仍會保持細線。若不需要此行為,請傳入 1.0 等正的 width。

弧線從 start_angle 朝 end_angle 繪製,因此 start_angle < end_angle 時為順時針,否則為逆時針。以相反順序傳入相同角度,會產生相同的弧線。若 start_angle 和 end_angle 的絕對差大於 @GDScript.TAU 弧度,則會繪製完整橢圓(弧線不會與自身重疊)。


void draw_end_animation() 🔗

通過 draw_animation_slice() 提交所有動畫切片後,該函式可以被用來將繪製恢復到其預設狀態(所有後續繪製命令都將可見)。如果不關心這個特定用例,則不需要在提交切片後使用該函式。


void draw_lcd_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1)) 🔗

在給定的位置繪製一個帶有 LCD 子像素反鋸齒的字型紋理的矩形區域,可以選擇用一種顏色來調制。rect 定義在區域空間。

紋理是通過以下混合操作繪製的,CanvasItemMaterial 的混合模式被忽略:

dst.r = texture.r * modulate.r * modulate.a + dst.r * (1.0 - texture.r * modulate.a);
dst.g = texture.g * modulate.g * modulate.a + dst.g * (1.0 - texture.g * modulate.a);
dst.b = texture.b * modulate.b * modulate.a + dst.b * (1.0 - texture.b * modulate.a);
dst.a = modulate.a + dst.a * (1.0 - modulate.a);

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_line(from: Vector2, to: Vector2, color: Color, width: float = -1.0, antialiased: bool = false) 🔗

使用給定的顏色和寬度,從一個 2D 點到另一個點繪製一條直線。它可以選擇反鋸齒。from 位置和 to 位置定義在區域空間。另見 draw_dashed_line()、draw_multiline() 和 draw_polyline()。

如果 width 為負,則將繪製一個兩點圖元而不是一個四點圖元。這意味著當縮放 CanvasItem 時,線條將保持細長。如果不需要此行為,請傳遞一個正的 width,如 1.0。


void draw_mesh(mesh: Mesh, texture: Texture2D, transform: Transform2D = Transform2D(1, 0, 0, 1, 0, 0), modulate: Color = Color(1, 1, 1, 1)) 🔗

使用提供的紋理在 2D 中繪製一個Mesh。相關文件見 MeshInstance2D。transform 是在區域空間中定義的。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_msdf_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), outline: float = 0.0, pixel_range: float = 4.0, scale: float = 1.0) 🔗

在給定位置,繪製一條多通道有符號距離場紋理的紋理矩形區域,可以選擇用一種顏色來調制。rect 定義在區域空間。有關 MSDF 字型渲染的更多資訊和注意事項,請參閱 FontFile.multichannel_signed_distance_field。

如果 outline 為正,則區域中像素的每個 Alpha 通道值都被設定為 outline 半徑內真實距離的最大值。

pixel_range 的值應該與距離場紋理生成期間使用的值相同。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_multiline(points: PackedVector2Array, color: Color, width: float = -1.0, antialiased: bool = false) 🔗

Draws multiple disconnected lines with a uniform width and color. Each line is defined by two consecutive points from points array in local space, i.e. i-th segment consists of points[2 * i], points[2 * i + 1] endpoints. When drawing large amounts of lines, this is faster than using individual draw_line() calls. To draw interconnected lines, use draw_polyline() instead.

If width is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

Note: antialiased is only effective if width is greater than 0.0.


void draw_multiline_colors(points: PackedVector2Array, colors: PackedColorArray, width: float = -1.0, antialiased: bool = false) 🔗

Draws multiple disconnected lines with a uniform width and segment-by-segment coloring. Each segment is defined by two consecutive points from points array in local space and a corresponding color from colors array, i.e. i-th segment consists of points[2 * i], points[2 * i + 1] endpoints and has colors[i] color. When drawing large amounts of lines, this is faster than using individual draw_line() calls. To draw interconnected lines, use draw_polyline_colors() instead.

If width is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

Note: antialiased is only effective if width is greater than 0.0.


void draw_multiline_string(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, max_lines: int = -1, modulate: Color = Color(1, 1, 1, 1), brk_flags: BitField[LineBreakFlag] = 3, justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const 🔗

Breaks text into lines and draws it using the specified font at the pos in local space. pos.x indicates the left side of the column of text (including the full width even if the text is narrower, and regardless of alignment); pos.y indicates the vertical position of the baseline of the first line of text. The text will have its color multiplied by modulate. If width is greater than or equal to 0, the text will be clipped if it exceeds the specified width. If oversampling is greater than zero, it is used as font oversampling factor, otherwise viewport oversampling settings are used.


void draw_multiline_string_outline(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, max_lines: int = -1, size: int = 1, modulate: Color = Color(1, 1, 1, 1), brk_flags: BitField[LineBreakFlag] = 3, justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const 🔗

使用 font 字型分若干行繪製 text 文字的輪廓,以區域空間中的 pos 作為左上角。文字顏色會與 modulate 相乘。如果 width 大於等於 0,則文字超出該寬度的部分會被裁剪。如果 oversampling 大於零則會用作字型過取樣係數,否則使用視埠的過取樣設定。


void draw_multimesh(multimesh: MultiMesh, texture: Texture2D) 🔗

使用提供的紋理在 2D 中繪製一個MultiMesh。相關文件見 MultiMeshInstance2D。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_polygon(points: PackedVector2Array, colors: PackedColorArray, uvs: PackedVector2Array = PackedVector2Array(), texture: Texture2D = null) 🔗

繪製一個由任意數量的點構成的實心多邊形,凹凸均可。與 draw_colored_polygon() 不同,每個點的顏色都可以單獨修改。points 陣列定義在區域空間。另見 draw_polyline() 和 draw_polyline_colors()。如果需要更高的靈活度(例如能夠用到骨骼),請改用 RenderingServer.canvas_item_add_triangle_array()。

注意:如果你需要頻繁重繪同樣的多邊形,包含大量頂點,請考慮預先使用 Geometry2D.triangulate_polygon() 進行三角剖分計算,並使用 draw_mesh()、draw_multimesh() 或 RenderingServer.canvas_item_add_triangle_array()。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_polyline(points: PackedVector2Array, color: Color, width: float = -1.0, antialiased: bool = false) 🔗

使用一致的 color 和 width 以及可選的反鋸齒(僅支援正 width ),繪製相互連接的線段。points 陣列定義在區域空間。繪製大量線條時,這比使用單獨的 draw_line() 呼叫更快。要繪製不相連的的線段,請改用 draw_multiline()。另見 draw_polygon()。

如果 width 為負,則它將被忽略,並使用 RenderingServer.PRIMITIVE_LINE_STRIP 繪製該折線。這意味著當 CanvasItem 被縮放時,折線將保持為細線。如果不需要該行為,請傳入一個正的 width,如 1.0。


void draw_polyline_colors(points: PackedVector2Array, colors: PackedColorArray, width: float = -1.0, antialiased: bool = false) 🔗

繪製相連的線段,使用一致的寬度 width,按點指定顏色,還可以開啟反鋸齒(僅支援正的 width)。將顏色與線段上的點匹配時,使用的是 points 和 colors 的索引,即每條線段填充的都是在兩個端點之間顏色的漸變色。points 陣列定義在區域空間。繪製大量線段時,這種方法比使用 draw_line() 一條條畫要快。要繪製不相連的線段,請改用 draw_multiline_colors()。另見 draw_polygon()。

如果 width 為負,則它將被忽略,並使用 RenderingServer.PRIMITIVE_LINE_STRIP 繪製該折線。這意味著當 CanvasItem 被縮放時,折線將保持為細線。如果不需要該行為,請傳入一個正的 width,如 1.0。


void draw_primitive(points: PackedVector2Array, colors: PackedColorArray, uvs: PackedVector2Array, texture: Texture2D = null) 🔗

繪製自訂圖元。1 個點的是個點,2 個點的是線段,3 個點的是三角形,4 個點的是四邊形。如果沒有指定點或者指定了超過 4 個點,則不會繪製任何東西,只會輸出錯誤訊息。points 陣列定義在區域空間。另見 draw_line()、draw_polyline()、draw_polygon()、draw_rect()。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_rect(rect: Rect2, color: Color, filled: bool = true, width: float = -1.0, antialiased: bool = false) 🔗

Draws a rectangle. If filled is true, the rectangle will be filled with the color specified. If filled is false, the rectangle will be drawn as a stroke with the color and width specified. The rect is specified in local space. See also draw_texture_rect().

If width is negative, then two-point primitives will be drawn instead of four-point ones. This means that when the CanvasItem is scaled, the lines will remain thin. If this behavior is not desired, then pass a positive width like 1.0.

If antialiased is true, half transparent "feathers" will be attached to the boundary, making outlines smooth.

Note: width is only effective if filled is false.

Note: Unfilled rectangles drawn with a negative width may not display perfectly. For example, corners may be missing or brighter due to overlapping lines (for a translucent color).


void draw_set_transform(position: Vector2, rotation: float = 0.0, scale: Vector2 = Vector2(1, 1)) 🔗

使用分量設定用於繪圖的自訂區域變換。後續的繪製都會使用這個變換。

注意:FontFile.oversampling 不會考慮 scale。這意味著將點陣圖字型及柵格化(非 MSDF)動態字型放大/縮小會產生模糊或像素化的結果。要讓文字無論如何縮放都保持清晰,可以啟用 MSDF 字型渲染,方法是啟用 ProjectSettings.gui/theme/default_font_multichannel_signed_distance_field(僅套用至預設專案字型),或者啟用自訂 DynamicFont 的多通道帶符號距離場匯入選項。對於系統字型,可以在屬性檢視器中啟用 SystemFont.multichannel_signed_distance_field。


void draw_set_transform_matrix(xform: Transform2D) 🔗

設定通過矩陣繪製時的自訂區域變換。此後繪製的任何東西都將被它變換。


void draw_string(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, modulate: Color = Color(1, 1, 1, 1), justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const 🔗

使用 font 字型繪製 text 文字,以區域空間中的 pos 作為左下角,對齊字型基線。文字顏色會與 modulate 相乘。如果 width 大於等於 0,則文字超出該寬度的部分會被裁剪。如果 oversampling 大於零則會用作字型過取樣係數,否則使用視埠的過取樣設定。

範例:使用專案預設字型繪製“Hello world”:

draw_string(ThemeDB.fallback_font, Vector2(64, 64), "Hello world", HORIZONTAL_ALIGNMENT_LEFT, -1, ThemeDB.fallback_font_size)

另見 Font.draw_string()。


void draw_string_outline(font: Font, pos: Vector2, text: String, alignment: HorizontalAlignment = 0, width: float = -1, font_size: int = 16, size: int = 1, modulate: Color = Color(1, 1, 1, 1), justification_flags: BitField[JustificationFlag] = 3, direction: Direction = 0, orientation: Orientation = 0, oversampling: float = 0.0) const 🔗

使用 font 字型繪製 text 文字的輪廓,以區域空間中的 pos 作為左下角,對齊字型基線。文字顏色會與 modulate 相乘。如果 width 大於等於 0,則文字超出該寬度的部分會被裁剪。如果 oversampling 大於零則會用作字型過取樣係數,否則使用視埠的過取樣設定。


void draw_style_box(style_box: StyleBox, rect: Rect2) 🔗

繪製一個樣式化的矩形。rect 在區域空間中定義。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_texture(texture: Texture2D, position: Vector2, modulate: Color = Color(1, 1, 1, 1)) 🔗

在給定位置繪製紋理。position 是在區域空間中定義的。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_texture_rect(texture: Texture2D, rect: Rect2, tile: bool, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false) 🔗

在給定位置繪製一個帶紋理的矩形,可以選擇用顏色調制。rect 定義在區域空間。如果 transpose 為 true,則紋理將交換其 X 和 Y 座標。另見 draw_rect() 和 draw_texture_rect_region()。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void draw_texture_rect_region(texture: Texture2D, rect: Rect2, src_rect: Rect2, modulate: Color = Color(1, 1, 1, 1), transpose: bool = false, clip_uv: bool = true) 🔗

在給定的區域空間位置繪製具有紋理的矩形,可以指定所使用的紋理區域(由 src_rect 指定),可選擇用顏色調制。如果 transpose 為 true,則紋理將交換其 X 和 Y 座標。另見 draw_texture_rect()。

注意:在 GDScript 中,不應將僅儲存在區域變數中的樣式框、紋理和網格與該方法一起使用,因為呼叫該方法後繪製操作不會立即開始。在 GDScript 中,當使用區域變數的函式結束時,區域變數會在渲染髮生之前被銷毀。


void force_update_transform() 🔗

強制更新節點的變換。如果節點不在樹中則失敗。另見 get_transform()。

注意:出於效能考慮,通常會對變換的更新進行累積,在影格結束時應用一次。更新也會沿著 CanvasItem 子節點傳播。因此只應在確實需要最新的變換時使用該方法(例如進行物理運算)。


RID get_canvas() const 🔗

回傳該節點注冊到的 World2D 畫布的 RID,適用於 RenderingServer。


RID get_canvas_item() const 🔗

回傳 RenderingServer 對該項目使用的畫布項目 RID。


CanvasLayer get_canvas_layer_node() const 🔗

回傳包含該節點的 CanvasLayer,如果該節點不在任何 CanvasLayer 中,則回傳 null。


Transform2D get_canvas_transform() const 🔗

回傳節點的變換,從所在畫布的座標系轉換至所在視埠的座標系。另見 Node.get_viewport()。


Vector2 get_global_mouse_position() const 🔗

回傳滑鼠游標的全域位置,相對於包含該節點的 CanvasLayer。

注意:要得到螢幕空間的座標(例如使用非嵌入式 Popup 時)可以使用 DisplayServer.mouse_get_position()。


Transform2D get_global_transform() const 🔗

返回該專案的全域變換矩陣,即到最頂層的 CanvasItem 節點的綜合變換。最頂層的專案是一個 CanvasItem,它要麼沒有父級,要麼有非 CanvasItem 父級,或者要麼它啟用了 top_level。


Transform2D get_global_transform_with_canvas() const 🔗

Returns the transform from the local coordinate system of this CanvasItem to the Viewport's coordinate system.


Variant get_instance_shader_parameter(name: StringName) const 🔗

取得在該實例上設定的著色器參數值。


Vector2 get_local_mouse_position() const 🔗

返回該 CanvasItem 中滑鼠的位置,使用該 CanvasItem 的區域座標系。


Transform2D get_screen_transform() const 🔗

回傳該 CanvasItem 在全域螢幕座標中的變換(即考慮視窗位置)。主要用於編輯器外掛。

對於嵌入視窗(見 Viewport.gui_embed_subwindows),則等同於 get_global_transform_with_canvas()。


Transform2D get_transform() const 🔗

回傳該 CanvasItem 的變換矩陣。


Rect2 get_viewport_rect() const 🔗

以 Rect2 的形式回傳該節點的視埠邊界。另見 Node.get_viewport()。


Transform2D get_viewport_transform() const 🔗

回傳該節點的變換,從所注冊畫布的座標系轉換至視埠嵌入器的座標系。另見 Viewport.get_final_transform() 和 Node.get_viewport()。


bool get_visibility_layer_bit(layer: int) const 🔗

如果 visibility_layer 中設定了給定索引對應的層,則回傳 true。


World2D get_world_2d() const 🔗

回傳該節點注冊到的 World2D。

通常與該節點的視埠相同(見 Node.get_viewport() 和 Viewport.find_world_2d())。


void hide() 🔗

如果該 CanvasItem 目前是可見的,則將其隱藏。相當於將 visible 設為 false。


bool is_local_transform_notification_enabled() const 🔗

如果節點會在區域變換發生改變時收到 NOTIFICATION_LOCAL_TRANSFORM_CHANGED 則回傳 true。使用 set_notify_local_transform() 啟用。


bool is_transform_notification_enabled() const 🔗

如果節點會在全域變換發生改變時收到 NOTIFICATION_TRANSFORM_CHANGED 則回傳 true。使用 set_notify_transform() 啟用。


bool is_visible_in_tree() const 🔗

如果節點存在於 SceneTree 中,並且 visible 屬性為 true、所有祖級節點也都可見,則回傳 true。如果存在隱藏的祖級節點,則該節點在場景樹中不可見,因此不會進行繪製(見 _draw())。

父節點派生自 CanvasItem、CanvasLayer 或 Window 時才會進行可見性檢查。如果父節點為其他型別(例如 Node、AnimationPlayer、Node3D),則會當作可見。

注意:該方法不會考慮 visibility_layer,因此即便回傳 true,最後也可能不渲染該節點。


Vector2 make_canvas_position_local(viewport_point: Vector2) const 🔗

將 viewport_point 從視埠座標系變換到該節點的區域座標系。

要進行相反的操作,請使用 get_global_transform_with_canvas()。

var viewport_point = get_global_transform_with_canvas() * local_point

InputEvent make_input_local(event: InputEvent) const 🔗

回傳 event 事件的副本,將其座標從全域空間轉換至該 CanvasItem 的區域空間。無法轉換則原樣回傳 InputEvent。


void move_to_front() 🔗

將該節點移至同級節點的下方,通常會導致該節點繪製在同級節點的上方。如果該節點沒有父節點則不會發生任何事情。另見 Node.move_child()。


void queue_redraw() 🔗

將該 CanvasItem 加入重繪佇列。空閒時,如果 CanvasItem 可見,則會發送 NOTIFICATION_DRAW 並呼叫 _draw()。即便多次呼叫這個方法,每影格也都只會發生一次繪製。


void set_instance_shader_parameter(name: StringName, value: Variant) 🔗

設定著色器 Uniform 的值,僅限此實例 (每實例 Uniform)。另請參閱 ShaderMaterial.set_shader_parameter(),以在使用相同 ShaderMaterial 的所有實例上指派 Uniform。

注意: 著色器 Uniform 若要能夠按每個實例指派,它在著色器程式碼中 必須 定義為 instance uniform ...,而非 uniform ...。

注意: name 區分大小寫,且必須與程式碼中 Uniform 的名稱完全相符 (而非屬性檢視器中大寫的名稱)。


void set_notify_local_transform(enable: bool) 🔗

如果為 true,則該節點將在其區域變換發生改變時收到 NOTIFICATION_LOCAL_TRANSFORM_CHANGED。

注意:Bone2D、CollisionShape2D 等許多畫布項都會自動啟用,從而正常工作。


void set_notify_transform(enable: bool) 🔗

如果為 true,則該節點將在其全域變換發生改變時收到 NOTIFICATION_TRANSFORM_CHANGED。

注意:Camera2D、Light2D 等許多畫布項都會自動啟用該功能,以便正常執行。


void set_visibility_layer_bit(layer: int, enabled: bool) 🔗

Set/clear individual bits on the rendering visibility layer (layer is between 0 and 31). This simplifies editing this CanvasItem's visibility layer compared to assigning the visibility_layer property directly.


void show() 🔗

如果該 CanvasItem 目前是隱藏的,則將其顯示。相當於將 visible 設為 true。

注意:對於繼承自 Popup 的控制項,讓它們可見的正確做法是換成呼叫各種 popup*() 函式。