CanvasLayer

Inherits:Node<Object

Inherited By:ParallaxBackground

A node used for independent rendering of objects within a 2D scene.

Description

CanvasItem-derived nodes that are direct or indirect children of aCanvasLayer will be drawn in that layer. The layer is a numeric index that defines the draw order. The default 2D scene renders with index0, so aCanvasLayer with index-1 will be drawn below, and aCanvasLayer with index1 will be drawn above. This order will hold regardless of theCanvasItem.z_index of the nodes within each layer.

CanvasLayers can be hidden and they can also optionally follow the viewport. This makes them useful for HUDs like health bar overlays (on layers1 and higher) or backgrounds (on layers-1 and lower).

Note: EmbeddedWindows are placed on layer1024.CanvasItems on layers1025 and higher appear in front of embedded windows.

Note: EachCanvasLayer is drawn on one specificViewport and cannot be shared between multipleViewports, seecustom_viewport. When using multipleViewports, for example in a split-screen game, you need create an individualCanvasLayer for eachViewport you want it to be drawn on.

Tutorials

Properties

Node

custom_viewport

bool

follow_viewport_enabled

false

float

follow_viewport_scale

1.0

int

layer

1

Vector2

offset

Vector2(0,0)

float

rotation

0.0

Vector2

scale

Vector2(1,1)

Transform2D

transform

Transform2D(1,0,0,1,0,0)

bool

visible

true

Methods

RID

get_canvas()const

Transform2D

get_final_transform()const

void

hide()

void

show()


Signals

visibility_changed()🔗

Emitted when visibility of the layer is changed. Seevisible.


Property Descriptions

Nodecustom_viewport🔗

The customViewport node assigned to theCanvasLayer. Ifnull, uses the default viewport instead.


boolfollow_viewport_enabled =false🔗

If enabled, theCanvasLayer stays in a fixed position on the screen. If disabled, theCanvasLayer maintains its position in world space.

Together withfollow_viewport_scale, this can be used for a pseudo-3D effect.


floatfollow_viewport_scale =1.0🔗

Scales the layer when usingfollow_viewport_enabled. Layers moving into the foreground should have increasing scales, while layers moving into the background should have decreasing scales.


intlayer =1🔗

Layer index for draw order. Lower values are drawn behind higher values.

Note: If multiple CanvasLayers have the same layer index,CanvasItem children of one CanvasLayer are drawn behind theCanvasItem children of the other CanvasLayer. Which CanvasLayer is drawn in front is non-deterministic.


Vector2offset =Vector2(0,0)🔗

The layer's base offset.


floatrotation =0.0🔗

The layer's rotation in radians.


Vector2scale =Vector2(1,1)🔗

The layer's scale.


Transform2Dtransform =Transform2D(1,0,0,1,0,0)🔗

The layer's transform.


boolvisible =true🔗

Iffalse, anyCanvasItem under thisCanvasLayer will be hidden.

UnlikeCanvasItem.visible, visibility of aCanvasLayer isn't propagated to underlying layers.


Method Descriptions

RIDget_canvas()const🔗

Returns the RID of the canvas used by this layer.


Transform2Dget_final_transform()const🔗

Returns the transform from theCanvasLayers coordinate system to theViewports coordinate system.


voidhide()🔗

Hides anyCanvasItem under thisCanvasLayer. This is equivalent to settingvisible tofalse.


voidshow()🔗

Shows anyCanvasItem under thisCanvasLayer. This is equivalent to settingvisible totrue.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.