class_node2d.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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:`RemoteTransform2D<class_remotetransform2d>`, :ref:`Joint2D<class_joint2d>`, :ref:`VisibilityNotifier2D<class_visibilitynotifier2d>`, :ref:`Navigation2D<class_navigation2d>`, :ref:`CollisionPolygon2D<class_collisionpolygon2d>`, :ref:`TouchScreenButton<class_touchscreenbutton>`, :ref:`Particles2D<class_particles2d>`, :ref:`AnimatedSprite<class_animatedsprite>`, :ref:`RayCast2D<class_raycast2d>`, :ref:`Light2D<class_light2d>`, :ref:`Path2D<class_path2d>`, :ref:`Line2D<class_line2d>`, :ref:`Position2D<class_position2d>`, :ref:`AudioStreamPlayer2D<class_audiostreamplayer2d>`, :ref:`CanvasModulate<class_canvasmodulate>`, :ref:`Sprite<class_sprite>`, :ref:`CollisionShape2D<class_collisionshape2d>`, :ref:`NavigationPolygonInstance<class_navigationpolygoninstance>`, :ref:`PathFollow2D<class_pathfollow2d>`, :ref:`ParallaxLayer<class_parallaxlayer>`, :ref:`Polygon2D<class_polygon2d>`, :ref:`LightOccluder2D<class_lightoccluder2d>`, :ref:`CollisionObject2D<class_collisionobject2d>`, :ref:`BackBufferCopy<class_backbuffercopy>`, :ref:`YSort<class_ysort>`, :ref:`TileMap<class_tilemap>`, :ref:`Camera2D<class_camera2d>`
  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. Member Functions
  14. ----------------
  15. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  16. | void | :ref:`apply_scale<class_Node2D_apply_scale>` **(** :ref:`Vector2<class_vector2>` ratio **)** |
  17. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  18. | void | :ref:`edit_set_pivot<class_Node2D_edit_set_pivot>` **(** :ref:`Vector2<class_vector2>` pivot **)** |
  19. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_get_angle_to>` **(** :ref:`Vector2<class_vector2>` point **)** const |
  21. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`Vector2<class_vector2>` | :ref:`get_global_position<class_Node2D_get_global_position>` **(** **)** const |
  23. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`float<class_float>` | :ref:`get_global_rotation<class_Node2D_get_global_rotation>` **(** **)** const |
  25. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`float<class_float>` | :ref:`get_global_rotation_in_degrees<class_Node2D_get_global_rotation_in_degrees>` **(** **)** const |
  27. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`Vector2<class_vector2>` | :ref:`get_global_scale<class_Node2D_get_global_scale>` **(** **)** const |
  29. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Vector2<class_vector2>` | :ref:`get_position<class_Node2D_get_position>` **(** **)** const |
  31. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`Transform2D<class_transform2d>` | :ref:`get_relative_transform_to_parent<class_Node2D_get_relative_transform_to_parent>` **(** :ref:`Node<class_node>` parent **)** const |
  33. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`get_rotation<class_Node2D_get_rotation>` **(** **)** const |
  35. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_rotation_in_degrees<class_Node2D_get_rotation_in_degrees>` **(** **)** const |
  37. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_vector2>` | :ref:`get_scale<class_Node2D_get_scale>` **(** **)** const |
  39. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_z<class_Node2D_get_z>` **(** **)** const |
  41. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`global_translate<class_Node2D_global_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  43. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_z_relative<class_Node2D_is_z_relative>` **(** **)** const |
  45. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  46. | void | :ref:`look_at<class_Node2D_look_at>` **(** :ref:`Vector2<class_vector2>` point **)** |
  47. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`move_local_x<class_Node2D_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  49. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  50. | void | :ref:`move_local_y<class_Node2D_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  51. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  52. | void | :ref:`rotate<class_Node2D_rotate>` **(** :ref:`float<class_float>` radians **)** |
  53. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`set_global_position<class_Node2D_set_global_position>` **(** :ref:`Vector2<class_vector2>` position **)** |
  55. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`set_global_rotation<class_Node2D_set_global_rotation>` **(** :ref:`float<class_float>` radians **)** |
  57. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_global_rotation_in_degrees<class_Node2D_set_global_rotation_in_degrees>` **(** :ref:`float<class_float>` degrees **)** |
  59. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_global_scale<class_Node2D_set_global_scale>` **(** :ref:`Vector2<class_vector2>` scale **)** |
  61. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  62. | void | :ref:`set_global_transform<class_Node2D_set_global_transform>` **(** :ref:`Transform2D<class_transform2d>` xform **)** |
  63. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  64. | void | :ref:`set_position<class_Node2D_set_position>` **(** :ref:`Vector2<class_vector2>` position **)** |
  65. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  66. | void | :ref:`set_rotation<class_Node2D_set_rotation>` **(** :ref:`float<class_float>` radians **)** |
  67. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  68. | void | :ref:`set_rotation_in_degrees<class_Node2D_set_rotation_in_degrees>` **(** :ref:`float<class_float>` degrees **)** |
  69. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  70. | void | :ref:`set_scale<class_Node2D_set_scale>` **(** :ref:`Vector2<class_vector2>` scale **)** |
  71. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  72. | void | :ref:`set_transform<class_Node2D_set_transform>` **(** :ref:`Transform2D<class_transform2d>` xform **)** |
  73. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  74. | void | :ref:`set_z<class_Node2D_set_z>` **(** :ref:`int<class_int>` z **)** |
  75. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  76. | void | :ref:`set_z_as_relative<class_Node2D_set_z_as_relative>` **(** :ref:`bool<class_bool>` enable **)** |
  77. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Vector2<class_vector2>` | :ref:`to_global<class_Node2D_to_global>` **(** :ref:`Vector2<class_vector2>` local_point **)** const |
  79. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`Vector2<class_vector2>` | :ref:`to_local<class_Node2D_to_local>` **(** :ref:`Vector2<class_vector2>` global_point **)** const |
  81. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  82. | void | :ref:`translate<class_Node2D_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  83. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  84. Member Variables
  85. ----------------
  86. - :ref:`Vector2<class_vector2>` **global_position** - Global position.
  87. - :ref:`float<class_float>` **global_rotation** - Global rotation in radians.
  88. - :ref:`float<class_float>` **global_rotation_deg** - Global rotation in degrees.
  89. - :ref:`Vector2<class_vector2>` **global_scale** - Global scale.
  90. - :ref:`Transform2D<class_transform2d>` **global_transform** - Global [Transform2D].
  91. - :ref:`Vector2<class_vector2>` **position** - Position, relative to the node's parent.
  92. - :ref:`float<class_float>` **rotation** - Rotation in radians.
  93. - :ref:`float<class_float>` **rotation_deg** - Rotation in degrees.
  94. - :ref:`Vector2<class_vector2>` **scale** - Rotation in degrees.
  95. - :ref:`Transform2D<class_transform2d>` **transform** - Local [Transform2D].
  96. - :ref:`int<class_int>` **z** - Z-index. Controls the order in which the nodes render. A node with a higher Z-index will display in front of others.
  97. - :ref:`bool<class_bool>` **z_as_relative** - Make the node's Z-index 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.
  98. Description
  99. -----------
  100. 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.
  101. Member Function Description
  102. ---------------------------
  103. .. _class_Node2D_apply_scale:
  104. - void **apply_scale** **(** :ref:`Vector2<class_vector2>` ratio **)**
  105. Multiplies the current scale by the 'ratio' vector.
  106. .. _class_Node2D_edit_set_pivot:
  107. - void **edit_set_pivot** **(** :ref:`Vector2<class_vector2>` pivot **)**
  108. Set the pivot position of the 2D node to 'pivot' value. Only some Node2Ds implement this method.
  109. .. _class_Node2D_get_angle_to:
  110. - :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_vector2>` point **)** const
  111. Returns the angle between the node and the 'point' in radians.
  112. .. _class_Node2D_get_global_position:
  113. - :ref:`Vector2<class_vector2>` **get_global_position** **(** **)** const
  114. Returns the node's global position.
  115. .. _class_Node2D_get_global_rotation:
  116. - :ref:`float<class_float>` **get_global_rotation** **(** **)** const
  117. Returns the node's global rotation in radians.
  118. .. _class_Node2D_get_global_rotation_in_degrees:
  119. - :ref:`float<class_float>` **get_global_rotation_in_degrees** **(** **)** const
  120. Return the node's global rotation in degrees.
  121. .. _class_Node2D_get_global_scale:
  122. - :ref:`Vector2<class_vector2>` **get_global_scale** **(** **)** const
  123. Returns the node's global scale.
  124. .. _class_Node2D_get_position:
  125. - :ref:`Vector2<class_vector2>` **get_position** **(** **)** const
  126. Returns the node's position.
  127. .. _class_Node2D_get_relative_transform_to_parent:
  128. - :ref:`Transform2D<class_transform2d>` **get_relative_transform_to_parent** **(** :ref:`Node<class_node>` parent **)** const
  129. Returns the :ref:`Transform2D<class_transform2d>` relative to this node's parent.
  130. .. _class_Node2D_get_rotation:
  131. - :ref:`float<class_float>` **get_rotation** **(** **)** const
  132. Returns the node's rotation in radians.
  133. .. _class_Node2D_get_rotation_in_degrees:
  134. - :ref:`float<class_float>` **get_rotation_in_degrees** **(** **)** const
  135. Returns the node's rotation in degrees.
  136. .. _class_Node2D_get_scale:
  137. - :ref:`Vector2<class_vector2>` **get_scale** **(** **)** const
  138. Returns the node's scale.
  139. .. _class_Node2D_get_z:
  140. - :ref:`int<class_int>` **get_z** **(** **)** const
  141. Returns the node's Z-index.
  142. .. _class_Node2D_global_translate:
  143. - void **global_translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  144. Adds the 'offset' vector to the node's global position.
  145. .. _class_Node2D_is_z_relative:
  146. - :ref:`bool<class_bool>` **is_z_relative** **(** **)** const
  147. Returns true if this node's Z-index is relative to its parent's. Else, returns false.
  148. .. _class_Node2D_look_at:
  149. - void **look_at** **(** :ref:`Vector2<class_vector2>` point **)**
  150. Rotates the node so it points towards the 'point'.
  151. .. _class_Node2D_move_local_x:
  152. - void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  153. Apply a local translation on the node's X axis based on the process's 'delta'. If 'scaled' is false, normalizes the movement.
  154. .. _class_Node2D_move_local_y:
  155. - void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  156. Apply a local translation on the node's Y axis based on the process's 'delta'. If 'scaled' is false, normalizes the movement.
  157. .. _class_Node2D_rotate:
  158. - void **rotate** **(** :ref:`float<class_float>` radians **)**
  159. Apply a rotation to the node, in radians, starting from its current rotation.
  160. .. _class_Node2D_set_global_position:
  161. - void **set_global_position** **(** :ref:`Vector2<class_vector2>` position **)**
  162. Set the node's global position.
  163. .. _class_Node2D_set_global_rotation:
  164. - void **set_global_rotation** **(** :ref:`float<class_float>` radians **)**
  165. Set the node's global rotation in radians.
  166. .. _class_Node2D_set_global_rotation_in_degrees:
  167. - void **set_global_rotation_in_degrees** **(** :ref:`float<class_float>` degrees **)**
  168. Set the node's global rotation in degrees.
  169. .. _class_Node2D_set_global_scale:
  170. - void **set_global_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  171. Set the node's global scale.
  172. .. _class_Node2D_set_global_transform:
  173. - void **set_global_transform** **(** :ref:`Transform2D<class_transform2d>` xform **)**
  174. Set the node's global :ref:`Transform2D<class_transform2d>`.
  175. .. _class_Node2D_set_position:
  176. - void **set_position** **(** :ref:`Vector2<class_vector2>` position **)**
  177. Set the node's position.
  178. .. _class_Node2D_set_rotation:
  179. - void **set_rotation** **(** :ref:`float<class_float>` radians **)**
  180. Set the node's rotation in radians.
  181. .. _class_Node2D_set_rotation_in_degrees:
  182. - void **set_rotation_in_degrees** **(** :ref:`float<class_float>` degrees **)**
  183. Set the node's rotation in degrees.
  184. .. _class_Node2D_set_scale:
  185. - void **set_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  186. Set the node's scale.
  187. .. _class_Node2D_set_transform:
  188. - void **set_transform** **(** :ref:`Transform2D<class_transform2d>` xform **)**
  189. Set the node's local :ref:`Transform2D<class_transform2d>`.
  190. .. _class_Node2D_set_z:
  191. - void **set_z** **(** :ref:`int<class_int>` z **)**
  192. Set the node's Z-index.
  193. .. _class_Node2D_set_z_as_relative:
  194. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` enable **)**
  195. Make the node's Z-index 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.
  196. .. _class_Node2D_to_global:
  197. - :ref:`Vector2<class_vector2>` **to_global** **(** :ref:`Vector2<class_vector2>` local_point **)** const
  198. .. _class_Node2D_to_local:
  199. - :ref:`Vector2<class_vector2>` **to_local** **(** :ref:`Vector2<class_vector2>` global_point **)** const
  200. .. _class_Node2D_translate:
  201. - void **translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  202. Translate the node locally by the 'offset' vector, starting from its current local position.