Files
godot-docs-l10n/classes/zh_Hant/class_canvaslayer.rst

329 lines
14 KiB
ReStructuredText

:github_url: hide
.. _class_CanvasLayer:
CanvasLayer
===========
**繼承:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
**被繼承:** :ref:`ParallaxBackground<class_ParallaxBackground>`
用於 2D 場景中的物件的獨立算繪的節點。
.. rst-class:: classref-introduction-group
說明
----
:ref:`CanvasItem<class_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<class_CanvasItem_property_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<class_Window>`\ s are placed on layer ``1024``. :ref:`CanvasItem<class_CanvasItem>`\ s on layers ``1025`` and higher appear in front of embedded windows.
\ **Note:** Each **CanvasLayer** is drawn on one specific :ref:`Viewport<class_Viewport>` and cannot be shared between multiple :ref:`Viewport<class_Viewport>`\ s, see :ref:`custom_viewport<class_CanvasLayer_property_custom_viewport>`. When using multiple :ref:`Viewport<class_Viewport>`\ s, for example in a split-screen game, you need to create an individual **CanvasLayer** for each :ref:`Viewport<class_Viewport>` you want it to be drawn on.
.. rst-class:: classref-introduction-group
教學
----
- :doc:`Viewport 和畫布變換 <../tutorials/2d/2d_transforms>`
- :doc:`畫布層 <../tutorials/2d/canvas_layers>`
- `2D Dodge The Creeps 範例 <https://godotengine.org/asset-library/asset/2712>`__
.. rst-class:: classref-reftable-group
屬性
----
.. table::
:widths: auto
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`Node<class_Node>` | :ref:`custom_viewport<class_CanvasLayer_property_custom_viewport>` | |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`bool<class_bool>` | :ref:`follow_viewport_enabled<class_CanvasLayer_property_follow_viewport_enabled>` | ``false`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`float<class_float>` | :ref:`follow_viewport_scale<class_CanvasLayer_property_follow_viewport_scale>` | ``1.0`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`int<class_int>` | :ref:`layer<class_CanvasLayer_property_layer>` | ``1`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`offset<class_CanvasLayer_property_offset>` | ``Vector2(0, 0)`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`float<class_float>` | :ref:`rotation<class_CanvasLayer_property_rotation>` | ``0.0`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`scale<class_CanvasLayer_property_scale>` | ``Vector2(1, 1)`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`Transform2D<class_Transform2D>` | :ref:`transform<class_CanvasLayer_property_transform>` | ``Transform2D(1, 0, 0, 1, 0, 0)`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
| :ref:`bool<class_bool>` | :ref:`visible<class_CanvasLayer_property_visible>` | ``true`` |
+---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+---------------------------------------+----------------------------------------------------------------------------------------+
| :ref:`RID<class_RID>` | :ref:`get_canvas<class_CanvasLayer_method_get_canvas>`\ (\ ) |const| |
+---------------------------------------+----------------------------------------------------------------------------------------+
| :ref:`Transform2D<class_Transform2D>` | :ref:`get_final_transform<class_CanvasLayer_method_get_final_transform>`\ (\ ) |const| |
+---------------------------------------+----------------------------------------------------------------------------------------+
| |void| | :ref:`hide<class_CanvasLayer_method_hide>`\ (\ ) |
+---------------------------------------+----------------------------------------------------------------------------------------+
| |void| | :ref:`show<class_CanvasLayer_method_show>`\ (\ ) |
+---------------------------------------+----------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
訊號
----
.. _class_CanvasLayer_signal_visibility_changed:
.. rst-class:: classref-signal
**visibility_changed**\ (\ ) :ref:`🔗<class_CanvasLayer_signal_visibility_changed>`
當該層的可見性發生變化時觸發。請參閱 :ref:`visible<class_CanvasLayer_property_visible>`\ 。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
屬性說明
--------
.. _class_CanvasLayer_property_custom_viewport:
.. rst-class:: classref-property
:ref:`Node<class_Node>` **custom_viewport** :ref:`🔗<class_CanvasLayer_property_custom_viewport>`
.. rst-class:: classref-property-setget
- |void| **set_custom_viewport**\ (\ value\: :ref:`Node<class_Node>`\ )
- :ref:`Node<class_Node>` **get_custom_viewport**\ (\ )
分配給該 **CanvasLayer** 的自訂 :ref:`Viewport<class_Viewport>` 節點。如果為 ``null``\ ,則使用預設的視口。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_follow_viewport_enabled:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **follow_viewport_enabled** = ``false`` :ref:`🔗<class_CanvasLayer_property_follow_viewport_enabled>`
.. rst-class:: classref-property-setget
- |void| **set_follow_viewport**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_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<class_CanvasLayer_property_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<class_float>` **follow_viewport_scale** = ``1.0`` :ref:`🔗<class_CanvasLayer_property_follow_viewport_scale>`
.. rst-class:: classref-property-setget
- |void| **set_follow_viewport_scale**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_follow_viewport_scale**\ (\ )
使用 :ref:`follow_viewport_enabled<class_CanvasLayer_property_follow_viewport_enabled>` 時縮放圖層。移入到前景的圖層應具有增加的縮放,而移入到背景的圖層應具有減小的縮放。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_layer:
.. rst-class:: classref-property
:ref:`int<class_int>` **layer** = ``1`` :ref:`🔗<class_CanvasLayer_property_layer>`
.. rst-class:: classref-property-setget
- |void| **set_layer**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_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<class_CanvasItem>` children of one CanvasLayer are drawn behind the :ref:`CanvasItem<class_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<class_RenderingServer_constant_CANVAS_LAYER_MIN>` and :ref:`RenderingServer.CANVAS_LAYER_MAX<class_RenderingServer_constant_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<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_CanvasLayer_property_offset>`
.. rst-class:: classref-property-setget
- |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
- :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
圖層的基本偏移量。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_rotation:
.. rst-class:: classref-property
:ref:`float<class_float>` **rotation** = ``0.0`` :ref:`🔗<class_CanvasLayer_property_rotation>`
.. rst-class:: classref-property-setget
- |void| **set_rotation**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_rotation**\ (\ )
圖層的旋轉弧度。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_scale:
.. rst-class:: classref-property
:ref:`Vector2<class_Vector2>` **scale** = ``Vector2(1, 1)`` :ref:`🔗<class_CanvasLayer_property_scale>`
.. rst-class:: classref-property-setget
- |void| **set_scale**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
- :ref:`Vector2<class_Vector2>` **get_scale**\ (\ )
圖層的縮放。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_transform:
.. rst-class:: classref-property
:ref:`Transform2D<class_Transform2D>` **transform** = ``Transform2D(1, 0, 0, 1, 0, 0)`` :ref:`🔗<class_CanvasLayer_property_transform>`
.. rst-class:: classref-property-setget
- |void| **set_transform**\ (\ value\: :ref:`Transform2D<class_Transform2D>`\ )
- :ref:`Transform2D<class_Transform2D>` **get_transform**\ (\ )
圖層的變換。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_property_visible:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **visible** = ``true`` :ref:`🔗<class_CanvasLayer_property_visible>`
.. rst-class:: classref-property-setget
- |void| **set_visible**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_visible**\ (\ )
``false`` 時,該 **CanvasLayer** 下的所有 :ref:`CanvasItem<class_CanvasItem>` 都會被隱藏。
:ref:`CanvasItem.visible<class_CanvasItem_property_visible>` 不同,\ **CanvasLayer** 的顯示與否不會傳播到其內部的層。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法說明
--------
.. _class_CanvasLayer_method_get_canvas:
.. rst-class:: classref-method
:ref:`RID<class_RID>` **get_canvas**\ (\ ) |const| :ref:`🔗<class_CanvasLayer_method_get_canvas>`
返回此層使用的畫布的 RID。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_method_get_final_transform:
.. rst-class:: classref-method
:ref:`Transform2D<class_Transform2D>` **get_final_transform**\ (\ ) |const| :ref:`🔗<class_CanvasLayer_method_get_final_transform>`
返回從 **CanvasLayer** 坐標系到 :ref:`Viewport<class_Viewport>` 坐標系的變換。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_method_hide:
.. rst-class:: classref-method
|void| **hide**\ (\ ) :ref:`🔗<class_CanvasLayer_method_hide>`
隱藏該 **CanvasLayer** 下的所有 :ref:`CanvasItem<class_CanvasItem>`\ 。相當於將 :ref:`visible<class_CanvasLayer_property_visible>` 設為 ``false``\ 。
.. rst-class:: classref-item-separator
----
.. _class_CanvasLayer_method_show:
.. rst-class:: classref-method
|void| **show**\ (\ ) :ref:`🔗<class_CanvasLayer_method_show>`
顯示該 **CanvasLayer** 下的所有 :ref:`CanvasItem<class_CanvasItem>`\ 。相當於將 :ref:`visible<class_CanvasLayer_property_visible>` 設為 ``true``\ 。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要使用者覆寫才能生效。)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (本方法沒有副作用。不會修改該實例的任何成員變數。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了這裡描述的參數外,還可以接受任意數量的參數。)`
.. |constructor| replace:: :abbr:`constructor (本方法用於建構一個型別。)`
.. |static| replace:: :abbr:`static (本方法無需實例即可呼叫,因此可以直接使用類別名稱呼叫。)`
.. |operator| replace:: :abbr:`operator (本方法描述將本型別作為左運算元時可用的有效運算子。)`
.. |bitfield| replace:: :abbr:`BitField (此值是由下列旗標組成的位元遮罩整數。)`
.. |void| replace:: :abbr:`void (無回傳值。)`