:github_url: hide .. _class_CanvasLayer: CanvasLayer =========== **Hereda:** :ref:`Node` **<** :ref:`Object` **Heredado por:** :ref:`ParallaxBackground` A node used for independent rendering of objects within a 2D scene. .. rst-class:: classref-introduction-group Descripción ---------------------- :ref:`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 :ref:`CanvasItem.z_index` of the nodes within each layer. \ **CanvasLayer**\ s 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 :ref:`Window`\ s are placed on layer ``1024``. :ref:`CanvasItem`\ s on layers ``1025`` and higher appear in front of embedded windows. \ **Note:** Each **CanvasLayer** is drawn on one specific :ref:`Viewport` and cannot be shared between multiple :ref:`Viewport`\ s, see :ref:`custom_viewport`. When using multiple :ref:`Viewport`\ s, for example in a split-screen game, you need to create an individual **CanvasLayer** for each :ref:`Viewport` you want it to be drawn on. .. rst-class:: classref-introduction-group Tutoriales -------------------- - :doc:`Viewport and canvas transforms <../tutorials/2d/2d_transforms>` - :doc:`Capas del canvas <../tutorials/2d/canvas_layers>` - `Demo de Dodge The Creeps en 2D `__ .. rst-class:: classref-reftable-group Propiedades ---------------------- .. table:: :widths: auto +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`Node` | :ref:`custom_viewport` | | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`bool` | :ref:`follow_viewport_enabled` | ``false`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`float` | :ref:`follow_viewport_scale` | ``1.0`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`int` | :ref:`layer` | ``1`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`Vector2` | :ref:`offset` | ``Vector2(0, 0)`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`float` | :ref:`rotation` | ``0.0`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`Vector2` | :ref:`scale` | ``Vector2(1, 1)`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`Transform2D` | :ref:`transform` | ``Transform2D(1, 0, 0, 1, 0, 0)`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ | :ref:`bool` | :ref:`visible` | ``true`` | +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+ .. rst-class:: classref-reftable-group Métodos -------------- .. table:: :widths: auto +---------------------------------------+----------------------------------------------------------------------------------------+ | :ref:`RID` | :ref:`get_canvas`\ (\ ) |const| | +---------------------------------------+----------------------------------------------------------------------------------------+ | :ref:`Transform2D` | :ref:`get_final_transform`\ (\ ) |const| | +---------------------------------------+----------------------------------------------------------------------------------------+ | |void| | :ref:`hide`\ (\ ) | +---------------------------------------+----------------------------------------------------------------------------------------+ | |void| | :ref:`show`\ (\ ) | +---------------------------------------+----------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Señales -------------- .. _class_CanvasLayer_signal_visibility_changed: .. rst-class:: classref-signal **visibility_changed**\ (\ ) :ref:`🔗` Emitida cuando se modifica la visibilidad de la capa. Véase :ref:`visible`. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Descripciones de Propiedades -------------------------------------------------------- .. _class_CanvasLayer_property_custom_viewport: .. rst-class:: classref-property :ref:`Node` **custom_viewport** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_custom_viewport**\ (\ value\: :ref:`Node`\ ) - :ref:`Node` **get_custom_viewport**\ (\ ) El nodo personalizado :ref:`Viewport` asignado al **CanvasLayer**. Si ``null``, utiliza en su lugar la vista por defecto. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_follow_viewport_enabled: .. rst-class:: classref-property :ref:`bool` **follow_viewport_enabled** = ``false`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_follow_viewport**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_following_viewport**\ (\ ) If enabled, the **CanvasLayer** maintains its position in world space. If disabled, the **CanvasLayer** stays in a fixed position on the screen. Together with :ref:`follow_viewport_scale`, this can be used for a pseudo-3D effect. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_follow_viewport_scale: .. rst-class:: classref-property :ref:`float` **follow_viewport_scale** = ``1.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_follow_viewport_scale**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_follow_viewport_scale**\ (\ ) Scales the layer when using :ref:`follow_viewport_enabled`. Layers moving into the foreground should have increasing scales, while layers moving into the background should have decreasing scales. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_layer: .. rst-class:: classref-property :ref:`int` **layer** = ``1`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_layer**\ (\ value\: :ref:`int`\ ) - :ref:`int` **get_layer**\ (\ ) Layer index for draw order. Lower values are drawn behind higher values. \ **Note:** If multiple CanvasLayers have the same layer index, :ref:`CanvasItem` children of one CanvasLayer are drawn behind the :ref:`CanvasItem` children of the other CanvasLayer. Which CanvasLayer is drawn in front is non-deterministic. \ **Note:** The layer index should be between :ref:`RenderingServer.CANVAS_LAYER_MIN` and :ref:`RenderingServer.CANVAS_LAYER_MAX` (inclusive). Any other value will wrap around. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_offset: .. rst-class:: classref-property :ref:`Vector2` **offset** = ``Vector2(0, 0)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_offset**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_offset**\ (\ ) El desplazamiento de la capa base. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_rotation: .. rst-class:: classref-property :ref:`float` **rotation** = ``0.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_rotation**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_rotation**\ (\ ) La rotación de la capa en radianes. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_scale: .. rst-class:: classref-property :ref:`Vector2` **scale** = ``Vector2(1, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_scale**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_scale**\ (\ ) La escala de la capa. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_transform: .. rst-class:: classref-property :ref:`Transform2D` **transform** = ``Transform2D(1, 0, 0, 1, 0, 0)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_transform**\ (\ value\: :ref:`Transform2D`\ ) - :ref:`Transform2D` **get_transform**\ (\ ) La transformación de la capa. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_property_visible: .. rst-class:: classref-property :ref:`bool` **visible** = ``true`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_visible**\ (\ value\: :ref:`bool`\ ) - :ref:`bool` **is_visible**\ (\ ) If ``false``, any :ref:`CanvasItem` under this **CanvasLayer** will be hidden. Unlike :ref:`CanvasItem.visible`, visibility of a **CanvasLayer** isn't propagated to underlying layers. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Descripciones de Métodos ------------------------------------------------ .. _class_CanvasLayer_method_get_canvas: .. rst-class:: classref-method :ref:`RID` **get_canvas**\ (\ ) |const| :ref:`🔗` Devuelve el RID del canvas usado por esta capa. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_method_get_final_transform: .. rst-class:: classref-method :ref:`Transform2D` **get_final_transform**\ (\ ) |const| :ref:`🔗` Returns the transform from the **CanvasLayer**\ s coordinate system to the :ref:`Viewport`\ s coordinate system. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_method_hide: .. rst-class:: classref-method |void| **hide**\ (\ ) :ref:`🔗` Hides any :ref:`CanvasItem` under this **CanvasLayer**. This is equivalent to setting :ref:`visible` to ``false``. .. rst-class:: classref-item-separator ---- .. _class_CanvasLayer_method_show: .. rst-class:: classref-method |void| **show**\ (\ ) :ref:`🔗` Shows any :ref:`CanvasItem` under this **CanvasLayer**. This is equivalent to setting :ref:`visible` to ``true``. .. |virtual| replace:: :abbr:`virtual (Normalmente, este método debería ser sobreescrito por el usuario para que tenga algún efecto.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (Este método no tiene efectos secundarios. No modifica ninguna de las variables miembro de la instancia.)` .. |vararg| replace:: :abbr:`vararg (Este método permite agregar cualquier número de argumentos después de los descritos aquí.)` .. |constructor| replace:: :abbr:`constructor (Este método se utiliza para construir un tipo.)` .. |static| replace:: :abbr:`static (Este método no necesita una instancia para ser llamado, por lo que puede llamarse directamente utilizando el nombre de la clase.)` .. |operator| replace:: :abbr:`operator (Este método describe un operador válido para usar con este tipo como operando izquierdo.)` .. |bitfield| replace:: :abbr:`BitField (Este valor es un entero compuesto como una máscara de bits de las siguientes banderas.)` .. |void| replace:: :abbr:`void (Sin valor de retorno.)`