class_canvaslayer.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/CanvasLayer.xml.
  6. .. _class_CanvasLayer:
  7. CanvasLayer
  8. ===========
  9. **Inherits:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`ParallaxBackground<class_ParallaxBackground>`
  11. A node used for independent rendering of objects within a 2D scene.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. :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.
  16. \ **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).
  17. \ **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.
  18. \ **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 create an individual **CanvasLayer** for each :ref:`Viewport<class_Viewport>` you want it to be drawn on.
  19. .. rst-class:: classref-introduction-group
  20. Tutorials
  21. ---------
  22. - :doc:`Viewport and canvas transforms <../tutorials/2d/2d_transforms>`
  23. - :doc:`Canvas layers <../tutorials/2d/canvas_layers>`
  24. - `2D Dodge The Creeps Demo <https://godotengine.org/asset-library/asset/2712>`__
  25. .. rst-class:: classref-reftable-group
  26. Properties
  27. ----------
  28. .. table::
  29. :widths: auto
  30. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  31. | :ref:`Node<class_Node>` | :ref:`custom_viewport<class_CanvasLayer_property_custom_viewport>` | |
  32. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  33. | :ref:`bool<class_bool>` | :ref:`follow_viewport_enabled<class_CanvasLayer_property_follow_viewport_enabled>` | ``false`` |
  34. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  35. | :ref:`float<class_float>` | :ref:`follow_viewport_scale<class_CanvasLayer_property_follow_viewport_scale>` | ``1.0`` |
  36. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  37. | :ref:`int<class_int>` | :ref:`layer<class_CanvasLayer_property_layer>` | ``1`` |
  38. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_CanvasLayer_property_offset>` | ``Vector2(0, 0)`` |
  40. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  41. | :ref:`float<class_float>` | :ref:`rotation<class_CanvasLayer_property_rotation>` | ``0.0`` |
  42. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`scale<class_CanvasLayer_property_scale>` | ``Vector2(1, 1)`` |
  44. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  45. | :ref:`Transform2D<class_Transform2D>` | :ref:`transform<class_CanvasLayer_property_transform>` | ``Transform2D(1, 0, 0, 1, 0, 0)`` |
  46. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`visible<class_CanvasLayer_property_visible>` | ``true`` |
  48. +---------------------------------------+------------------------------------------------------------------------------------+-----------------------------------+
  49. .. rst-class:: classref-reftable-group
  50. Methods
  51. -------
  52. .. table::
  53. :widths: auto
  54. +---------------------------------------+----------------------------------------------------------------------------------------+
  55. | :ref:`RID<class_RID>` | :ref:`get_canvas<class_CanvasLayer_method_get_canvas>`\ (\ ) |const| |
  56. +---------------------------------------+----------------------------------------------------------------------------------------+
  57. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_final_transform<class_CanvasLayer_method_get_final_transform>`\ (\ ) |const| |
  58. +---------------------------------------+----------------------------------------------------------------------------------------+
  59. | |void| | :ref:`hide<class_CanvasLayer_method_hide>`\ (\ ) |
  60. +---------------------------------------+----------------------------------------------------------------------------------------+
  61. | |void| | :ref:`show<class_CanvasLayer_method_show>`\ (\ ) |
  62. +---------------------------------------+----------------------------------------------------------------------------------------+
  63. .. rst-class:: classref-section-separator
  64. ----
  65. .. rst-class:: classref-descriptions-group
  66. Signals
  67. -------
  68. .. _class_CanvasLayer_signal_visibility_changed:
  69. .. rst-class:: classref-signal
  70. **visibility_changed**\ (\ ) :ref:`🔗<class_CanvasLayer_signal_visibility_changed>`
  71. Emitted when visibility of the layer is changed. See :ref:`visible<class_CanvasLayer_property_visible>`.
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Property Descriptions
  76. ---------------------
  77. .. _class_CanvasLayer_property_custom_viewport:
  78. .. rst-class:: classref-property
  79. :ref:`Node<class_Node>` **custom_viewport** :ref:`🔗<class_CanvasLayer_property_custom_viewport>`
  80. .. rst-class:: classref-property-setget
  81. - |void| **set_custom_viewport**\ (\ value\: :ref:`Node<class_Node>`\ )
  82. - :ref:`Node<class_Node>` **get_custom_viewport**\ (\ )
  83. The custom :ref:`Viewport<class_Viewport>` node assigned to the **CanvasLayer**. If ``null``, uses the default viewport instead.
  84. .. rst-class:: classref-item-separator
  85. ----
  86. .. _class_CanvasLayer_property_follow_viewport_enabled:
  87. .. rst-class:: classref-property
  88. :ref:`bool<class_bool>` **follow_viewport_enabled** = ``false`` :ref:`🔗<class_CanvasLayer_property_follow_viewport_enabled>`
  89. .. rst-class:: classref-property-setget
  90. - |void| **set_follow_viewport**\ (\ value\: :ref:`bool<class_bool>`\ )
  91. - :ref:`bool<class_bool>` **is_following_viewport**\ (\ )
  92. 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.
  93. Together with :ref:`follow_viewport_scale<class_CanvasLayer_property_follow_viewport_scale>` it can be used for a pseudo 3D effect.
  94. .. rst-class:: classref-item-separator
  95. ----
  96. .. _class_CanvasLayer_property_follow_viewport_scale:
  97. .. rst-class:: classref-property
  98. :ref:`float<class_float>` **follow_viewport_scale** = ``1.0`` :ref:`🔗<class_CanvasLayer_property_follow_viewport_scale>`
  99. .. rst-class:: classref-property-setget
  100. - |void| **set_follow_viewport_scale**\ (\ value\: :ref:`float<class_float>`\ )
  101. - :ref:`float<class_float>` **get_follow_viewport_scale**\ (\ )
  102. Scales the layer when using :ref:`follow_viewport_enabled<class_CanvasLayer_property_follow_viewport_enabled>`. Layers moving into the foreground should have increasing scales, while layers moving into the background should have decreasing scales.
  103. .. rst-class:: classref-item-separator
  104. ----
  105. .. _class_CanvasLayer_property_layer:
  106. .. rst-class:: classref-property
  107. :ref:`int<class_int>` **layer** = ``1`` :ref:`🔗<class_CanvasLayer_property_layer>`
  108. .. rst-class:: classref-property-setget
  109. - |void| **set_layer**\ (\ value\: :ref:`int<class_int>`\ )
  110. - :ref:`int<class_int>` **get_layer**\ (\ )
  111. Layer index for draw order. Lower values are drawn behind higher values.
  112. \ **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.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. _class_CanvasLayer_property_offset:
  116. .. rst-class:: classref-property
  117. :ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_CanvasLayer_property_offset>`
  118. .. rst-class:: classref-property-setget
  119. - |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  120. - :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
  121. The layer's base offset.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. _class_CanvasLayer_property_rotation:
  125. .. rst-class:: classref-property
  126. :ref:`float<class_float>` **rotation** = ``0.0`` :ref:`🔗<class_CanvasLayer_property_rotation>`
  127. .. rst-class:: classref-property-setget
  128. - |void| **set_rotation**\ (\ value\: :ref:`float<class_float>`\ )
  129. - :ref:`float<class_float>` **get_rotation**\ (\ )
  130. The layer's rotation in radians.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_CanvasLayer_property_scale:
  134. .. rst-class:: classref-property
  135. :ref:`Vector2<class_Vector2>` **scale** = ``Vector2(1, 1)`` :ref:`🔗<class_CanvasLayer_property_scale>`
  136. .. rst-class:: classref-property-setget
  137. - |void| **set_scale**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
  138. - :ref:`Vector2<class_Vector2>` **get_scale**\ (\ )
  139. The layer's scale.
  140. .. rst-class:: classref-item-separator
  141. ----
  142. .. _class_CanvasLayer_property_transform:
  143. .. rst-class:: classref-property
  144. :ref:`Transform2D<class_Transform2D>` **transform** = ``Transform2D(1, 0, 0, 1, 0, 0)`` :ref:`🔗<class_CanvasLayer_property_transform>`
  145. .. rst-class:: classref-property-setget
  146. - |void| **set_transform**\ (\ value\: :ref:`Transform2D<class_Transform2D>`\ )
  147. - :ref:`Transform2D<class_Transform2D>` **get_transform**\ (\ )
  148. The layer's transform.
  149. .. rst-class:: classref-item-separator
  150. ----
  151. .. _class_CanvasLayer_property_visible:
  152. .. rst-class:: classref-property
  153. :ref:`bool<class_bool>` **visible** = ``true`` :ref:`🔗<class_CanvasLayer_property_visible>`
  154. .. rst-class:: classref-property-setget
  155. - |void| **set_visible**\ (\ value\: :ref:`bool<class_bool>`\ )
  156. - :ref:`bool<class_bool>` **is_visible**\ (\ )
  157. If ``false``, any :ref:`CanvasItem<class_CanvasItem>` under this **CanvasLayer** will be hidden.
  158. Unlike :ref:`CanvasItem.visible<class_CanvasItem_property_visible>`, visibility of a **CanvasLayer** isn't propagated to underlying layers.
  159. .. rst-class:: classref-section-separator
  160. ----
  161. .. rst-class:: classref-descriptions-group
  162. Method Descriptions
  163. -------------------
  164. .. _class_CanvasLayer_method_get_canvas:
  165. .. rst-class:: classref-method
  166. :ref:`RID<class_RID>` **get_canvas**\ (\ ) |const| :ref:`🔗<class_CanvasLayer_method_get_canvas>`
  167. Returns the RID of the canvas used by this layer.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_CanvasLayer_method_get_final_transform:
  171. .. rst-class:: classref-method
  172. :ref:`Transform2D<class_Transform2D>` **get_final_transform**\ (\ ) |const| :ref:`🔗<class_CanvasLayer_method_get_final_transform>`
  173. Returns the transform from the **CanvasLayer**\ s coordinate system to the :ref:`Viewport<class_Viewport>`\ s coordinate system.
  174. .. rst-class:: classref-item-separator
  175. ----
  176. .. _class_CanvasLayer_method_hide:
  177. .. rst-class:: classref-method
  178. |void| **hide**\ (\ ) :ref:`🔗<class_CanvasLayer_method_hide>`
  179. Hides any :ref:`CanvasItem<class_CanvasItem>` under this **CanvasLayer**. This is equivalent to setting :ref:`visible<class_CanvasLayer_property_visible>` to ``false``.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. _class_CanvasLayer_method_show:
  183. .. rst-class:: classref-method
  184. |void| **show**\ (\ ) :ref:`🔗<class_CanvasLayer_method_show>`
  185. Shows any :ref:`CanvasItem<class_CanvasItem>` under this **CanvasLayer**. This is equivalent to setting :ref:`visible<class_CanvasLayer_property_visible>` to ``true``.
  186. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  187. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  188. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  189. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  190. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  191. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  192. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  193. .. |void| replace:: :abbr:`void (No return value.)`