class_node2d.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Node2D.xml.
  6. .. _class_Node2D:
  7. Node2D
  8. ======
  9. **Inherits:** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`AnimatedSprite<class_AnimatedSprite>`, :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>`, :ref:`BackBufferCopy<class_BackBufferCopy>`, :ref:`Bone2D<class_Bone2D>`, :ref:`Camera2D<class_Camera2D>`, :ref:`CanvasModulate<class_CanvasModulate>`, :ref:`CollisionObject2D<class_CollisionObject2D>`, :ref:`CollisionPolygon2D<class_CollisionPolygon2D>`, :ref:`CollisionShape2D<class_CollisionShape2D>`, :ref:`CPUParticles2D<class_CPUParticles2D>`, :ref:`Joint2D<class_Joint2D>`, :ref:`Light2D<class_Light2D>`, :ref:`LightOccluder2D<class_LightOccluder2D>`, :ref:`Line2D<class_Line2D>`, :ref:`Listener2D<class_Listener2D>`, :ref:`MeshInstance2D<class_MeshInstance2D>`, :ref:`MultiMeshInstance2D<class_MultiMeshInstance2D>`, :ref:`Navigation2D<class_Navigation2D>`, :ref:`NavigationPolygonInstance<class_NavigationPolygonInstance>`, :ref:`ParallaxLayer<class_ParallaxLayer>`, :ref:`Particles2D<class_Particles2D>`, :ref:`Path2D<class_Path2D>`, :ref:`PathFollow2D<class_PathFollow2D>`, :ref:`Polygon2D<class_Polygon2D>`, :ref:`Position2D<class_Position2D>`, :ref:`RayCast2D<class_RayCast2D>`, :ref:`RemoteTransform2D<class_RemoteTransform2D>`, :ref:`ShapeCast2D<class_ShapeCast2D>`, :ref:`Skeleton2D<class_Skeleton2D>`, :ref:`Sprite<class_Sprite>`, :ref:`TileMap<class_TileMap>`, :ref:`TouchScreenButton<class_TouchScreenButton>`, :ref:`VisibilityNotifier2D<class_VisibilityNotifier2D>`, :ref:`YSort<class_YSort>`
  11. A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Custom drawing in 2D <../tutorials/2d/custom_drawing_in_2d>`
  20. - `All 2D Demos <https://github.com/godotengine/godot-demo-projects/tree/master/2d>`__
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  27. | :ref:`Vector2<class_Vector2>` | :ref:`global_position<class_Node2D_property_global_position>` | |
  28. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  29. | :ref:`float<class_float>` | :ref:`global_rotation<class_Node2D_property_global_rotation>` | |
  30. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  31. | :ref:`float<class_float>` | :ref:`global_rotation_degrees<class_Node2D_property_global_rotation_degrees>` | |
  32. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  33. | :ref:`Vector2<class_Vector2>` | :ref:`global_scale<class_Node2D_property_global_scale>` | |
  34. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  35. | :ref:`Transform2D<class_Transform2D>` | :ref:`global_transform<class_Node2D_property_global_transform>` | |
  36. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  37. | :ref:`Vector2<class_Vector2>` | :ref:`position<class_Node2D_property_position>` | ``Vector2( 0, 0 )`` |
  38. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  39. | :ref:`float<class_float>` | :ref:`rotation<class_Node2D_property_rotation>` | ``0.0`` |
  40. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  41. | :ref:`float<class_float>` | :ref:`rotation_degrees<class_Node2D_property_rotation_degrees>` | ``0.0`` |
  42. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  43. | :ref:`Vector2<class_Vector2>` | :ref:`scale<class_Node2D_property_scale>` | ``Vector2( 1, 1 )`` |
  44. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  45. | :ref:`Transform2D<class_Transform2D>` | :ref:`transform<class_Node2D_property_transform>` | |
  46. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  47. | :ref:`bool<class_bool>` | :ref:`z_as_relative<class_Node2D_property_z_as_relative>` | ``true`` |
  48. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  49. | :ref:`int<class_int>` | :ref:`z_index<class_Node2D_property_z_index>` | ``0`` |
  50. +---------------------------------------+-------------------------------------------------------------------------------+---------------------+
  51. .. rst-class:: classref-reftable-group
  52. Methods
  53. -------
  54. .. table::
  55. :widths: auto
  56. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`apply_scale<class_Node2D_method_apply_scale>` **(** :ref:`Vector2<class_Vector2>` ratio **)** |
  58. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_method_get_angle_to>` **(** :ref:`Vector2<class_Vector2>` point **)** |const| |
  60. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_relative_transform_to_parent<class_Node2D_method_get_relative_transform_to_parent>` **(** :ref:`Node<class_Node>` parent **)** |const| |
  62. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`global_translate<class_Node2D_method_global_translate>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  64. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`look_at<class_Node2D_method_look_at>` **(** :ref:`Vector2<class_Vector2>` point **)** |
  66. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`move_local_x<class_Node2D_method_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  68. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`move_local_y<class_Node2D_method_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  70. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`rotate<class_Node2D_method_rotate>` **(** :ref:`float<class_float>` radians **)** |
  72. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Vector2<class_Vector2>` | :ref:`to_global<class_Node2D_method_to_global>` **(** :ref:`Vector2<class_Vector2>` local_point **)** |const| |
  74. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Vector2<class_Vector2>` | :ref:`to_local<class_Node2D_method_to_local>` **(** :ref:`Vector2<class_Vector2>` global_point **)** |const| |
  76. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | void | :ref:`translate<class_Node2D_method_translate>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  78. +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+
  79. .. rst-class:: classref-section-separator
  80. ----
  81. .. rst-class:: classref-descriptions-group
  82. Property Descriptions
  83. ---------------------
  84. .. _class_Node2D_property_global_position:
  85. .. rst-class:: classref-property
  86. :ref:`Vector2<class_Vector2>` **global_position**
  87. .. rst-class:: classref-property-setget
  88. - void **set_global_position** **(** :ref:`Vector2<class_Vector2>` value **)**
  89. - :ref:`Vector2<class_Vector2>` **get_global_position** **(** **)**
  90. Global position.
  91. .. rst-class:: classref-item-separator
  92. ----
  93. .. _class_Node2D_property_global_rotation:
  94. .. rst-class:: classref-property
  95. :ref:`float<class_float>` **global_rotation**
  96. .. rst-class:: classref-property-setget
  97. - void **set_global_rotation** **(** :ref:`float<class_float>` value **)**
  98. - :ref:`float<class_float>` **get_global_rotation** **(** **)**
  99. Global rotation in radians.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_Node2D_property_global_rotation_degrees:
  103. .. rst-class:: classref-property
  104. :ref:`float<class_float>` **global_rotation_degrees**
  105. .. rst-class:: classref-property-setget
  106. - void **set_global_rotation_degrees** **(** :ref:`float<class_float>` value **)**
  107. - :ref:`float<class_float>` **get_global_rotation_degrees** **(** **)**
  108. Global rotation in degrees.
  109. .. rst-class:: classref-item-separator
  110. ----
  111. .. _class_Node2D_property_global_scale:
  112. .. rst-class:: classref-property
  113. :ref:`Vector2<class_Vector2>` **global_scale**
  114. .. rst-class:: classref-property-setget
  115. - void **set_global_scale** **(** :ref:`Vector2<class_Vector2>` value **)**
  116. - :ref:`Vector2<class_Vector2>` **get_global_scale** **(** **)**
  117. Global scale.
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_Node2D_property_global_transform:
  121. .. rst-class:: classref-property
  122. :ref:`Transform2D<class_Transform2D>` **global_transform**
  123. .. rst-class:: classref-property-setget
  124. - void **set_global_transform** **(** :ref:`Transform2D<class_Transform2D>` value **)**
  125. - :ref:`Transform2D<class_Transform2D>` **get_global_transform** **(** **)**
  126. Global :ref:`Transform2D<class_Transform2D>`.
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_Node2D_property_position:
  130. .. rst-class:: classref-property
  131. :ref:`Vector2<class_Vector2>` **position** = ``Vector2( 0, 0 )``
  132. .. rst-class:: classref-property-setget
  133. - void **set_position** **(** :ref:`Vector2<class_Vector2>` value **)**
  134. - :ref:`Vector2<class_Vector2>` **get_position** **(** **)**
  135. Position, relative to the node's parent.
  136. .. rst-class:: classref-item-separator
  137. ----
  138. .. _class_Node2D_property_rotation:
  139. .. rst-class:: classref-property
  140. :ref:`float<class_float>` **rotation** = ``0.0``
  141. .. rst-class:: classref-property-setget
  142. - void **set_rotation** **(** :ref:`float<class_float>` value **)**
  143. - :ref:`float<class_float>` **get_rotation** **(** **)**
  144. Rotation in radians, relative to the node's parent.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_Node2D_property_rotation_degrees:
  148. .. rst-class:: classref-property
  149. :ref:`float<class_float>` **rotation_degrees** = ``0.0``
  150. .. rst-class:: classref-property-setget
  151. - void **set_rotation_degrees** **(** :ref:`float<class_float>` value **)**
  152. - :ref:`float<class_float>` **get_rotation_degrees** **(** **)**
  153. Rotation in degrees, relative to the node's parent.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_Node2D_property_scale:
  157. .. rst-class:: classref-property
  158. :ref:`Vector2<class_Vector2>` **scale** = ``Vector2( 1, 1 )``
  159. .. rst-class:: classref-property-setget
  160. - void **set_scale** **(** :ref:`Vector2<class_Vector2>` value **)**
  161. - :ref:`Vector2<class_Vector2>` **get_scale** **(** **)**
  162. The node's scale. Unscaled value: ``(1, 1)``.
  163. \ **Note:** Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_Node2D_property_transform:
  167. .. rst-class:: classref-property
  168. :ref:`Transform2D<class_Transform2D>` **transform**
  169. .. rst-class:: classref-property-setget
  170. - void **set_transform** **(** :ref:`Transform2D<class_Transform2D>` value **)**
  171. - :ref:`Transform2D<class_Transform2D>` **get_transform** **(** **)**
  172. Local :ref:`Transform2D<class_Transform2D>`.
  173. .. rst-class:: classref-item-separator
  174. ----
  175. .. _class_Node2D_property_z_as_relative:
  176. .. rst-class:: classref-property
  177. :ref:`bool<class_bool>` **z_as_relative** = ``true``
  178. .. rst-class:: classref-property-setget
  179. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` value **)**
  180. - :ref:`bool<class_bool>` **is_z_relative** **(** **)**
  181. If ``true``, the node's Z index is relative to its parent's Z index. If this node's Z index is 2 and its parent's effective Z index is 3, then this node's effective Z index will be 2 + 3 = 5.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_Node2D_property_z_index:
  185. .. rst-class:: classref-property
  186. :ref:`int<class_int>` **z_index** = ``0``
  187. .. rst-class:: classref-property-setget
  188. - void **set_z_index** **(** :ref:`int<class_int>` value **)**
  189. - :ref:`int<class_int>` **get_z_index** **(** **)**
  190. Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between :ref:`VisualServer.CANVAS_ITEM_Z_MIN<class_VisualServer_constant_CANVAS_ITEM_Z_MIN>` and :ref:`VisualServer.CANVAS_ITEM_Z_MAX<class_VisualServer_constant_CANVAS_ITEM_Z_MAX>` (inclusive).
  191. .. rst-class:: classref-section-separator
  192. ----
  193. .. rst-class:: classref-descriptions-group
  194. Method Descriptions
  195. -------------------
  196. .. _class_Node2D_method_apply_scale:
  197. .. rst-class:: classref-method
  198. void **apply_scale** **(** :ref:`Vector2<class_Vector2>` ratio **)**
  199. Multiplies the current scale by the ``ratio`` vector.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_Node2D_method_get_angle_to:
  203. .. rst-class:: classref-method
  204. :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_Vector2>` point **)** |const|
  205. Returns the angle between the node and the ``point`` in radians.
  206. \ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/node2d_get_angle_to.png>`__
  207. .. rst-class:: classref-item-separator
  208. ----
  209. .. _class_Node2D_method_get_relative_transform_to_parent:
  210. .. rst-class:: classref-method
  211. :ref:`Transform2D<class_Transform2D>` **get_relative_transform_to_parent** **(** :ref:`Node<class_Node>` parent **)** |const|
  212. Returns the :ref:`Transform2D<class_Transform2D>` relative to this node's parent.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. _class_Node2D_method_global_translate:
  216. .. rst-class:: classref-method
  217. void **global_translate** **(** :ref:`Vector2<class_Vector2>` offset **)**
  218. Adds the ``offset`` vector to the node's global position.
  219. .. rst-class:: classref-item-separator
  220. ----
  221. .. _class_Node2D_method_look_at:
  222. .. rst-class:: classref-method
  223. void **look_at** **(** :ref:`Vector2<class_Vector2>` point **)**
  224. Rotates the node so it points towards the ``point``, which is expected to use global coordinates.
  225. .. rst-class:: classref-item-separator
  226. ----
  227. .. _class_Node2D_method_move_local_x:
  228. .. rst-class:: classref-method
  229. void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  230. Applies a local translation on the node's X axis based on the :ref:`Node._process<class_Node_method__process>`'s ``delta``. If ``scaled`` is ``false``, normalizes the movement.
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _class_Node2D_method_move_local_y:
  234. .. rst-class:: classref-method
  235. void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  236. Applies a local translation on the node's Y axis based on the :ref:`Node._process<class_Node_method__process>`'s ``delta``. If ``scaled`` is ``false``, normalizes the movement.
  237. .. rst-class:: classref-item-separator
  238. ----
  239. .. _class_Node2D_method_rotate:
  240. .. rst-class:: classref-method
  241. void **rotate** **(** :ref:`float<class_float>` radians **)**
  242. Applies a rotation to the node, in radians, starting from its current rotation.
  243. .. rst-class:: classref-item-separator
  244. ----
  245. .. _class_Node2D_method_to_global:
  246. .. rst-class:: classref-method
  247. :ref:`Vector2<class_Vector2>` **to_global** **(** :ref:`Vector2<class_Vector2>` local_point **)** |const|
  248. Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to the **Node2D** it is called on. e.g. Applying this method to the positions of child nodes will correctly transform their positions into the global coordinate space, but applying it to a node's own position will give an incorrect result, as it will incorporate the node's own transformation into its global position.
  249. .. rst-class:: classref-item-separator
  250. ----
  251. .. _class_Node2D_method_to_local:
  252. .. rst-class:: classref-method
  253. :ref:`Vector2<class_Vector2>` **to_local** **(** :ref:`Vector2<class_Vector2>` global_point **)** |const|
  254. Transforms the provided global position into a position in local coordinate space. The output will be local relative to the **Node2D** it is called on. e.g. It is appropriate for determining the positions of child nodes, but it is not appropriate for determining its own position relative to its parent.
  255. .. rst-class:: classref-item-separator
  256. ----
  257. .. _class_Node2D_method_translate:
  258. .. rst-class:: classref-method
  259. void **translate** **(** :ref:`Vector2<class_Vector2>` offset **)**
  260. Translates the node by the given ``offset`` in local coordinates.
  261. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  262. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  263. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  264. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`