class_node2d.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Node2D.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Node2D:
  5. Node2D
  6. ======
  7. **Inherits:** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  8. **Inherited By:** :ref:`AnimatedSprite<class_AnimatedSprite>`, :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>`, :ref:`BackBufferCopy<class_BackBufferCopy>`, :ref:`Bone2D<class_Bone2D>`, :ref:`CPUParticles2D<class_CPUParticles2D>`, :ref:`Camera2D<class_Camera2D>`, :ref:`CanvasModulate<class_CanvasModulate>`, :ref:`CollisionObject2D<class_CollisionObject2D>`, :ref:`CollisionPolygon2D<class_CollisionPolygon2D>`, :ref:`CollisionShape2D<class_CollisionShape2D>`, :ref:`Joint2D<class_Joint2D>`, :ref:`Light2D<class_Light2D>`, :ref:`LightOccluder2D<class_LightOccluder2D>`, :ref:`Line2D<class_Line2D>`, :ref:`MeshInstance2D<class_MeshInstance2D>`, :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:`Skeleton2D<class_Skeleton2D>`, :ref:`Sprite<class_Sprite>`, :ref:`TileMap<class_TileMap>`, :ref:`TouchScreenButton<class_TouchScreenButton>`, :ref:`VisibilityNotifier2D<class_VisibilityNotifier2D>`, :ref:`YSort<class_YSort>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.
  13. Properties
  14. ----------
  15. +---------------------------------------+-------------------------------------------------------------------------------+
  16. | :ref:`Vector2<class_Vector2>` | :ref:`global_position<class_Node2D_property_global_position>` |
  17. +---------------------------------------+-------------------------------------------------------------------------------+
  18. | :ref:`float<class_float>` | :ref:`global_rotation<class_Node2D_property_global_rotation>` |
  19. +---------------------------------------+-------------------------------------------------------------------------------+
  20. | :ref:`float<class_float>` | :ref:`global_rotation_degrees<class_Node2D_property_global_rotation_degrees>` |
  21. +---------------------------------------+-------------------------------------------------------------------------------+
  22. | :ref:`Vector2<class_Vector2>` | :ref:`global_scale<class_Node2D_property_global_scale>` |
  23. +---------------------------------------+-------------------------------------------------------------------------------+
  24. | :ref:`Transform2D<class_Transform2D>` | :ref:`global_transform<class_Node2D_property_global_transform>` |
  25. +---------------------------------------+-------------------------------------------------------------------------------+
  26. | :ref:`Vector2<class_Vector2>` | :ref:`position<class_Node2D_property_position>` |
  27. +---------------------------------------+-------------------------------------------------------------------------------+
  28. | :ref:`float<class_float>` | :ref:`rotation<class_Node2D_property_rotation>` |
  29. +---------------------------------------+-------------------------------------------------------------------------------+
  30. | :ref:`float<class_float>` | :ref:`rotation_degrees<class_Node2D_property_rotation_degrees>` |
  31. +---------------------------------------+-------------------------------------------------------------------------------+
  32. | :ref:`Vector2<class_Vector2>` | :ref:`scale<class_Node2D_property_scale>` |
  33. +---------------------------------------+-------------------------------------------------------------------------------+
  34. | :ref:`Transform2D<class_Transform2D>` | :ref:`transform<class_Node2D_property_transform>` |
  35. +---------------------------------------+-------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`z_as_relative<class_Node2D_property_z_as_relative>` |
  37. +---------------------------------------+-------------------------------------------------------------------------------+
  38. | :ref:`int<class_int>` | :ref:`z_index<class_Node2D_property_z_index>` |
  39. +---------------------------------------+-------------------------------------------------------------------------------+
  40. Methods
  41. -------
  42. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`apply_scale<class_Node2D_method_apply_scale>` **(** :ref:`Vector2<class_Vector2>` ratio **)** |
  44. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_method_get_angle_to>` **(** :ref:`Vector2<class_Vector2>` point **)** const |
  46. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Transform2D<class_Transform2D>` | :ref:`get_relative_transform_to_parent<class_Node2D_method_get_relative_transform_to_parent>` **(** :ref:`Node<class_Node>` parent **)** const |
  48. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`global_translate<class_Node2D_method_global_translate>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  50. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`look_at<class_Node2D_method_look_at>` **(** :ref:`Vector2<class_Vector2>` point **)** |
  52. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`move_local_x<class_Node2D_method_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  54. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`move_local_y<class_Node2D_method_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  56. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`rotate<class_Node2D_method_rotate>` **(** :ref:`float<class_float>` radians **)** |
  58. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Vector2<class_Vector2>` | :ref:`to_global<class_Node2D_method_to_global>` **(** :ref:`Vector2<class_Vector2>` local_point **)** const |
  60. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Vector2<class_Vector2>` | :ref:`to_local<class_Node2D_method_to_local>` **(** :ref:`Vector2<class_Vector2>` global_point **)** const |
  62. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`translate<class_Node2D_method_translate>` **(** :ref:`Vector2<class_Vector2>` offset **)** |
  64. +---------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  65. Description
  66. -----------
  67. A 2D game object, with a position, rotation and scale. All 2D physics nodes and sprites inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control on the node's render order.
  68. Tutorials
  69. ---------
  70. - :doc:`../tutorials/2d/custom_drawing_in_2d`
  71. Property Descriptions
  72. ---------------------
  73. .. _class_Node2D_property_global_position:
  74. - :ref:`Vector2<class_Vector2>` **global_position**
  75. +----------+----------------------------+
  76. | *Setter* | set_global_position(value) |
  77. +----------+----------------------------+
  78. | *Getter* | get_global_position() |
  79. +----------+----------------------------+
  80. Global position.
  81. .. _class_Node2D_property_global_rotation:
  82. - :ref:`float<class_float>` **global_rotation**
  83. +----------+----------------------------+
  84. | *Setter* | set_global_rotation(value) |
  85. +----------+----------------------------+
  86. | *Getter* | get_global_rotation() |
  87. +----------+----------------------------+
  88. Global rotation in radians.
  89. .. _class_Node2D_property_global_rotation_degrees:
  90. - :ref:`float<class_float>` **global_rotation_degrees**
  91. +----------+------------------------------------+
  92. | *Setter* | set_global_rotation_degrees(value) |
  93. +----------+------------------------------------+
  94. | *Getter* | get_global_rotation_degrees() |
  95. +----------+------------------------------------+
  96. Global rotation in degrees.
  97. .. _class_Node2D_property_global_scale:
  98. - :ref:`Vector2<class_Vector2>` **global_scale**
  99. +----------+-------------------------+
  100. | *Setter* | set_global_scale(value) |
  101. +----------+-------------------------+
  102. | *Getter* | get_global_scale() |
  103. +----------+-------------------------+
  104. Global scale.
  105. .. _class_Node2D_property_global_transform:
  106. - :ref:`Transform2D<class_Transform2D>` **global_transform**
  107. +----------+-----------------------------+
  108. | *Setter* | set_global_transform(value) |
  109. +----------+-----------------------------+
  110. | *Getter* | get_global_transform() |
  111. +----------+-----------------------------+
  112. Global :ref:`Transform2D<class_Transform2D>`.
  113. .. _class_Node2D_property_position:
  114. - :ref:`Vector2<class_Vector2>` **position**
  115. +----------+---------------------+
  116. | *Setter* | set_position(value) |
  117. +----------+---------------------+
  118. | *Getter* | get_position() |
  119. +----------+---------------------+
  120. Position, relative to the node's parent.
  121. .. _class_Node2D_property_rotation:
  122. - :ref:`float<class_float>` **rotation**
  123. +----------+---------------------+
  124. | *Setter* | set_rotation(value) |
  125. +----------+---------------------+
  126. | *Getter* | get_rotation() |
  127. +----------+---------------------+
  128. Rotation in radians, relative to the node's parent.
  129. .. _class_Node2D_property_rotation_degrees:
  130. - :ref:`float<class_float>` **rotation_degrees**
  131. +----------+-----------------------------+
  132. | *Setter* | set_rotation_degrees(value) |
  133. +----------+-----------------------------+
  134. | *Getter* | get_rotation_degrees() |
  135. +----------+-----------------------------+
  136. Rotation in degrees, relative to the node's parent.
  137. .. _class_Node2D_property_scale:
  138. - :ref:`Vector2<class_Vector2>` **scale**
  139. +----------+------------------+
  140. | *Setter* | set_scale(value) |
  141. +----------+------------------+
  142. | *Getter* | get_scale() |
  143. +----------+------------------+
  144. The node's scale. Unscaled value: ``(1, 1)``
  145. .. _class_Node2D_property_transform:
  146. - :ref:`Transform2D<class_Transform2D>` **transform**
  147. +----------+----------------------+
  148. | *Setter* | set_transform(value) |
  149. +----------+----------------------+
  150. | *Getter* | get_transform() |
  151. +----------+----------------------+
  152. Local :ref:`Transform2D<class_Transform2D>`.
  153. .. _class_Node2D_property_z_as_relative:
  154. - :ref:`bool<class_bool>` **z_as_relative**
  155. +----------+--------------------------+
  156. | *Setter* | set_z_as_relative(value) |
  157. +----------+--------------------------+
  158. | *Getter* | is_z_relative() |
  159. +----------+--------------------------+
  160. 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.
  161. .. _class_Node2D_property_z_index:
  162. - :ref:`int<class_int>` **z_index**
  163. +----------+--------------------+
  164. | *Setter* | set_z_index(value) |
  165. +----------+--------------------+
  166. | *Getter* | get_z_index() |
  167. +----------+--------------------+
  168. Z-index. Controls the order in which the nodes render. A node with a higher Z-index will display in front of others.
  169. Method Descriptions
  170. -------------------
  171. .. _class_Node2D_method_apply_scale:
  172. - void **apply_scale** **(** :ref:`Vector2<class_Vector2>` ratio **)**
  173. Multiplies the current scale by the 'ratio' vector.
  174. .. _class_Node2D_method_get_angle_to:
  175. - :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_Vector2>` point **)** const
  176. Returns the angle between the node and the 'point' in radians.
  177. .. _class_Node2D_method_get_relative_transform_to_parent:
  178. - :ref:`Transform2D<class_Transform2D>` **get_relative_transform_to_parent** **(** :ref:`Node<class_Node>` parent **)** const
  179. Returns the :ref:`Transform2D<class_Transform2D>` relative to this node's parent.
  180. .. _class_Node2D_method_global_translate:
  181. - void **global_translate** **(** :ref:`Vector2<class_Vector2>` offset **)**
  182. Adds the 'offset' vector to the node's global position.
  183. .. _class_Node2D_method_look_at:
  184. - void **look_at** **(** :ref:`Vector2<class_Vector2>` point **)**
  185. Rotates the node so it points towards the 'point'.
  186. .. _class_Node2D_method_move_local_x:
  187. - void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  188. 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.
  189. .. _class_Node2D_method_move_local_y:
  190. - void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  191. 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.
  192. .. _class_Node2D_method_rotate:
  193. - void **rotate** **(** :ref:`float<class_float>` radians **)**
  194. Applies a rotation to the node, in radians, starting from its current rotation.
  195. .. _class_Node2D_method_to_global:
  196. - :ref:`Vector2<class_Vector2>` **to_global** **(** :ref:`Vector2<class_Vector2>` local_point **)** const
  197. Converts a local point's coordinates to global coordinates.
  198. .. _class_Node2D_method_to_local:
  199. - :ref:`Vector2<class_Vector2>` **to_local** **(** :ref:`Vector2<class_Vector2>` global_point **)** const
  200. Converts a global point's coordinates to local coordinates.
  201. .. _class_Node2D_method_translate:
  202. - void **translate** **(** :ref:`Vector2<class_Vector2>` offset **)**
  203. Translates the node by the given ``offset`` in local coordinates.