Class CanvasLayer
- Namespace
- Godot
- Assembly
- GodotSharp.dll
CanvasItem-derived nodes that are direct or indirect children of a CanvasLayer will be drawn in that layer. The layer is a numeric index that defines the draw order. The default 2D scene renders with index 0
, so a CanvasLayer with index -1
will be drawn below, and a CanvasLayer with index 1
will be drawn above. This order will hold regardless of the ZIndex 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 layers 1
and higher) or backgrounds (on layers -1
and lower).
Note: Embedded Windows are placed on layer 1024
. CanvasItems on layers 1025
and higher appear in front of embedded windows.
Note: Each CanvasLayer is drawn on one specific Viewport and cannot be shared between multiple Viewports, see CustomViewport. When using multiple Viewports, for example in a split-screen game, you need create an individual CanvasLayer for each Viewport you want it to be drawn on.
public class CanvasLayer : Node, IDisposable
- Inheritance
-
CanvasLayer
- Implements
- Derived
- Inherited Members
Constructors
CanvasLayer()
public CanvasLayer()
Properties
CustomViewport
The custom Viewport node assigned to the CanvasLayer. If null
, uses the default viewport instead.
public Node CustomViewport { get; set; }
Property Value
FollowViewportEnabled
If enabled, the CanvasLayer will use the viewport's transform, so it will move when camera moves instead of being anchored in a fixed position on the screen.
Together with FollowViewportScale it can be used for a pseudo 3D effect.
public bool FollowViewportEnabled { get; set; }
Property Value
FollowViewportScale
Scales the layer when using FollowViewportEnabled. Layers moving into the foreground should have increasing scales, while layers moving into the background should have decreasing scales.
public float FollowViewportScale { get; set; }
Property Value
Layer
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 the CanvasItem children of the other CanvasLayer. Which CanvasLayer is drawn in front is non-deterministic.
public int Layer { get; set; }
Property Value
Offset
The layer's base offset.
public Vector2 Offset { get; set; }
Property Value
Rotation
The layer's rotation in radians.
public float Rotation { get; set; }
Property Value
Scale
The layer's scale.
public Vector2 Scale { get; set; }
Property Value
Transform
The layer's transform.
public Transform2D Transform { get; set; }
Property Value
Visible
If false
, any CanvasItem under this CanvasLayer will be hidden.
Unlike Visible, visibility of a CanvasLayer isn't propagated to underlying layers.
public bool Visible { get; set; }
Property Value
Methods
GetCanvas()
Returns the RID of the canvas used by this layer.
public Rid GetCanvas()
Returns
GetFinalTransform()
Returns the transform from the CanvasLayers coordinate system to the Viewports coordinate system.
public Transform2D GetFinalTransform()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
Hide()
Hides any CanvasItem under this CanvasLayer. This is equivalent to setting Visible to false
.
public void Hide()
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Show()
Shows any CanvasItem under this CanvasLayer. This is equivalent to setting Visible to true
.
public void Show()
Events
VisibilityChanged
Emitted when visibility of the layer is changed. See Visible.
public event Action VisibilityChanged