class_node2d.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Node2D:
  4. Node2D
  5. ======
  6. **Inherits:** :ref:`CanvasItem<class_canvasitem>` **<** :ref:`Node<class_node>` **<** :ref:`Object<class_object>`
  7. **Inherited By:** :ref:`RemoteTransform2D<class_remotetransform2d>`, :ref:`Joint2D<class_joint2d>`, :ref:`ParallaxLayer<class_parallaxlayer>`, :ref:`Line2D<class_line2d>`, :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:`Light2D<class_light2d>`, :ref:`Path2D<class_path2d>`, :ref:`AudioStreamPlayer2D<class_audiostreamplayer2d>`, :ref:`Sprite<class_sprite>`, :ref:`RayCast2D<class_raycast2d>`, :ref:`CollisionShape2D<class_collisionshape2d>`, :ref:`NavigationPolygonInstance<class_navigationpolygoninstance>`, :ref:`PathFollow2D<class_pathfollow2d>`, :ref:`Polygon2D<class_polygon2d>`, :ref:`Position2D<class_position2d>`, :ref:`LightOccluder2D<class_lightoccluder2d>`, :ref:`CollisionObject2D<class_collisionobject2d>`, :ref:`BackBufferCopy<class_backbuffercopy>`, :ref:`CanvasModulate<class_canvasmodulate>`, :ref:`YSort<class_ysort>`, :ref:`TileMap<class_tilemap>`, :ref:`Camera2D<class_camera2d>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Base node for 2D system.
  12. Member Functions
  13. ----------------
  14. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  15. | void | :ref:`apply_scale<class_Node2D_apply_scale>` **(** :ref:`Vector2<class_vector2>` ratio **)** |
  16. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`edit_set_pivot<class_Node2D_edit_set_pivot>` **(** :ref:`Vector2<class_vector2>` pivot **)** |
  18. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_get_angle_to>` **(** :ref:`Vector2<class_vector2>` point **)** const |
  20. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`Vector2<class_vector2>` | :ref:`get_global_position<class_Node2D_get_global_position>` **(** **)** const |
  22. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`float<class_float>` | :ref:`get_global_rotation<class_Node2D_get_global_rotation>` **(** **)** const |
  24. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`float<class_float>` | :ref:`get_global_rotation_in_degrees<class_Node2D_get_global_rotation_in_degrees>` **(** **)** const |
  26. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Vector2<class_vector2>` | :ref:`get_global_scale<class_Node2D_get_global_scale>` **(** **)** const |
  28. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Vector2<class_vector2>` | :ref:`get_position<class_Node2D_get_position>` **(** **)** const |
  30. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Transform2D<class_transform2d>` | :ref:`get_relative_transform_to_parent<class_Node2D_get_relative_transform_to_parent>` **(** :ref:`Node<class_node>` parent **)** const |
  32. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`get_rotation<class_Node2D_get_rotation>` **(** **)** const |
  34. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`get_rotation_in_degrees<class_Node2D_get_rotation_in_degrees>` **(** **)** const |
  36. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Vector2<class_vector2>` | :ref:`get_scale<class_Node2D_get_scale>` **(** **)** const |
  38. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`get_z<class_Node2D_get_z>` **(** **)** const |
  40. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`global_translate<class_Node2D_global_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  42. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`is_z_relative<class_Node2D_is_z_relative>` **(** **)** const |
  44. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`look_at<class_Node2D_look_at>` **(** :ref:`Vector2<class_vector2>` point **)** |
  46. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`move_local_x<class_Node2D_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  48. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`move_local_y<class_Node2D_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  50. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`rotate<class_Node2D_rotate>` **(** :ref:`float<class_float>` radians **)** |
  52. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_global_position<class_Node2D_set_global_position>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  54. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_global_rotation<class_Node2D_set_global_rotation>` **(** :ref:`float<class_float>` radians **)** |
  56. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_global_rotation_in_degrees<class_Node2D_set_global_rotation_in_degrees>` **(** :ref:`float<class_float>` degrees **)** |
  58. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_global_scale<class_Node2D_set_global_scale>` **(** :ref:`Vector2<class_vector2>` scale **)** |
  60. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`set_global_transform<class_Node2D_set_global_transform>` **(** :ref:`Transform2D<class_transform2d>` xform **)** |
  62. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_position<class_Node2D_set_position>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  64. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_rotation<class_Node2D_set_rotation>` **(** :ref:`float<class_float>` radians **)** |
  66. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_rotation_in_degrees<class_Node2D_set_rotation_in_degrees>` **(** :ref:`float<class_float>` degrees **)** |
  68. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`set_scale<class_Node2D_set_scale>` **(** :ref:`Vector2<class_vector2>` scale **)** |
  70. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`set_transform<class_Node2D_set_transform>` **(** :ref:`Transform2D<class_transform2d>` xform **)** |
  72. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_z<class_Node2D_set_z>` **(** :ref:`int<class_int>` z **)** |
  74. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_z_as_relative<class_Node2D_set_z_as_relative>` **(** :ref:`bool<class_bool>` enable **)** |
  76. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`Vector2<class_vector2>` | :ref:`to_global<class_Node2D_to_global>` **(** :ref:`Vector2<class_vector2>` local_point **)** const |
  78. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Vector2<class_vector2>` | :ref:`to_local<class_Node2D_to_local>` **(** :ref:`Vector2<class_vector2>` global_point **)** const |
  80. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`translate<class_Node2D_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  82. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  83. Member Variables
  84. ----------------
  85. - :ref:`Vector2<class_vector2>` **global_position**
  86. - :ref:`float<class_float>` **global_rotation**
  87. - :ref:`float<class_float>` **global_rotation_deg**
  88. - :ref:`Vector2<class_vector2>` **global_scale**
  89. - :ref:`Transform2D<class_transform2d>` **global_transform**
  90. - :ref:`Vector2<class_vector2>` **position**
  91. - :ref:`float<class_float>` **rotation**
  92. - :ref:`float<class_float>` **rotation_deg**
  93. - :ref:`Vector2<class_vector2>` **scale**
  94. - :ref:`Transform2D<class_transform2d>` **transform**
  95. - :ref:`int<class_int>` **z**
  96. - :ref:`bool<class_bool>` **z_as_relative**
  97. Description
  98. -----------
  99. Base node for 2D system. Node2D contains a position, rotation and scale, which is used to position and animate. It can alternatively be used with a custom 2D transform (:ref:`Transform2D<class_transform2d>`). A tree of Node2Ds allows complex hierarchies for animation and positioning.
  100. Member Function Description
  101. ---------------------------
  102. .. _class_Node2D_apply_scale:
  103. - void **apply_scale** **(** :ref:`Vector2<class_vector2>` ratio **)**
  104. Apply the 'ratio' scale to the 2D node, according to its current scale value.
  105. .. _class_Node2D_edit_set_pivot:
  106. - void **edit_set_pivot** **(** :ref:`Vector2<class_vector2>` pivot **)**
  107. Set the pivot position of the 2D node to 'pivot' value. This method is implemented only in some nodes that inherit Node2D.
  108. .. _class_Node2D_get_angle_to:
  109. - :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_vector2>` point **)** const
  110. Return the rotation angle in radians needed for the 2d node to point at 'point' position.
  111. .. _class_Node2D_get_global_position:
  112. - :ref:`Vector2<class_vector2>` **get_global_position** **(** **)** const
  113. Return the global position of the 2D node.
  114. .. _class_Node2D_get_global_rotation:
  115. - :ref:`float<class_float>` **get_global_rotation** **(** **)** const
  116. Return the global rotation in radians of the 2D node.
  117. .. _class_Node2D_get_global_rotation_in_degrees:
  118. - :ref:`float<class_float>` **get_global_rotation_in_degrees** **(** **)** const
  119. Return the global rotation in degrees of the 2D node.
  120. .. _class_Node2D_get_global_scale:
  121. - :ref:`Vector2<class_vector2>` **get_global_scale** **(** **)** const
  122. Return the global scale of the 2D node.
  123. .. _class_Node2D_get_position:
  124. - :ref:`Vector2<class_vector2>` **get_position** **(** **)** const
  125. Return the position of the 2D node.
  126. .. _class_Node2D_get_relative_transform_to_parent:
  127. - :ref:`Transform2D<class_transform2d>` **get_relative_transform_to_parent** **(** :ref:`Node<class_node>` parent **)** const
  128. Return the transform :ref:`Transform2D<class_transform2d>` calculated relatively to the parent of this 2D node.
  129. .. _class_Node2D_get_rotation:
  130. - :ref:`float<class_float>` **get_rotation** **(** **)** const
  131. Return the rotation in radians of the 2D node.
  132. .. _class_Node2D_get_rotation_in_degrees:
  133. - :ref:`float<class_float>` **get_rotation_in_degrees** **(** **)** const
  134. Return the rotation in degrees of the 2D node.
  135. .. _class_Node2D_get_scale:
  136. - :ref:`Vector2<class_vector2>` **get_scale** **(** **)** const
  137. Return the scale of the 2D node.
  138. .. _class_Node2D_get_z:
  139. - :ref:`int<class_int>` **get_z** **(** **)** const
  140. Return the Z-index of the 2D node.
  141. .. _class_Node2D_global_translate:
  142. - void **global_translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  143. Apply a global translation of 'offset' to the 2D node, starting from its current global position.
  144. .. _class_Node2D_is_z_relative:
  145. - :ref:`bool<class_bool>` **is_z_relative** **(** **)** const
  146. Return true if the Z-index value of this 2D node is relative to its parent's. Else, return false.
  147. .. _class_Node2D_look_at:
  148. - void **look_at** **(** :ref:`Vector2<class_vector2>` point **)**
  149. Rotate the 2d node so it points at 'point' position.
  150. .. _class_Node2D_move_local_x:
  151. - void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  152. Apply a local translation on X axis to the 2D node according to the 'delta' of the process. If 'scaled' is false, the movement is normalized.
  153. .. _class_Node2D_move_local_y:
  154. - void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  155. Apply a local translation on Y axis to the 2D node according to the 'delta' of the process. If 'scaled' is false, the movement is normalized.
  156. .. _class_Node2D_rotate:
  157. - void **rotate** **(** :ref:`float<class_float>` radians **)**
  158. Apply a rotation (in radians) to the 2D node, starting from its current rotation.
  159. .. _class_Node2D_set_global_position:
  160. - void **set_global_position** **(** :ref:`Vector2<class_vector2>` pos **)**
  161. Set the global position of the 2D node.
  162. .. _class_Node2D_set_global_rotation:
  163. - void **set_global_rotation** **(** :ref:`float<class_float>` radians **)**
  164. Set the global rotation in radians of the 2D node
  165. .. _class_Node2D_set_global_rotation_in_degrees:
  166. - void **set_global_rotation_in_degrees** **(** :ref:`float<class_float>` degrees **)**
  167. Set the global rotation in degrees of the 2D node
  168. .. _class_Node2D_set_global_scale:
  169. - void **set_global_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  170. Set the global scale of the 2D node.
  171. .. _class_Node2D_set_global_transform:
  172. - void **set_global_transform** **(** :ref:`Transform2D<class_transform2d>` xform **)**
  173. Set the global transform :ref:`Transform2D<class_transform2d>` of the 2D node.
  174. .. _class_Node2D_set_position:
  175. - void **set_position** **(** :ref:`Vector2<class_vector2>` pos **)**
  176. Set the position of the 2D node.
  177. .. _class_Node2D_set_rotation:
  178. - void **set_rotation** **(** :ref:`float<class_float>` radians **)**
  179. Set the rotation in radians of the 2D node.
  180. .. _class_Node2D_set_rotation_in_degrees:
  181. - void **set_rotation_in_degrees** **(** :ref:`float<class_float>` degrees **)**
  182. Set the rotation in degrees of the 2D node.
  183. .. _class_Node2D_set_scale:
  184. - void **set_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  185. Set the scale of the 2D node.
  186. .. _class_Node2D_set_transform:
  187. - void **set_transform** **(** :ref:`Transform2D<class_transform2d>` xform **)**
  188. Set the local transform :ref:`Transform2D<class_transform2d>` of the 2D node.
  189. .. _class_Node2D_set_z:
  190. - void **set_z** **(** :ref:`int<class_int>` z **)**
  191. Set the Z-index value of the 2D node.
  192. .. _class_Node2D_set_z_as_relative:
  193. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` enable **)**
  194. Set the Z-index value as relative to the parent node of this 2D node. Thus, if this 2D node's Z-index value is 2 and its parent's effective Z-index is 3, then the effective Z-index value of this 2D node would be 3 + 2 = 5.
  195. .. _class_Node2D_to_global:
  196. - :ref:`Vector2<class_vector2>` **to_global** **(** :ref:`Vector2<class_vector2>` local_point **)** const
  197. .. _class_Node2D_to_local:
  198. - :ref:`Vector2<class_vector2>` **to_local** **(** :ref:`Vector2<class_vector2>` global_point **)** const
  199. .. _class_Node2D_translate:
  200. - void **translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  201. Apply a local translation of 'offset' to the 2D node, starting from its current local position.