class_node2d.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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:`ParticleAttractor2D<class_particleattractor2d>`, :ref:`CollisionObject2D<class_collisionobject2d>`, :ref:`VisibilityNotifier2D<class_visibilitynotifier2d>`, :ref:`TileMap<class_tilemap>`, :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:`SoundPlayer2D<class_soundplayer2d>`, :ref:`ViewportSprite<class_viewportsprite>`, :ref:`Path2D<class_path2d>`, :ref:`Sprite<class_sprite>`, :ref:`RayCast2D<class_raycast2d>`, :ref:`CollisionShape2D<class_collisionshape2d>`, :ref:`NavigationPolygonInstance<class_navigationpolygoninstance>`, :ref:`PathFollow2D<class_pathfollow2d>`, :ref:`ParallaxLayer<class_parallaxlayer>`, :ref:`Polygon2D<class_polygon2d>`, :ref:`Position2D<class_position2d>`, :ref:`LightOccluder2D<class_lightoccluder2d>`, :ref:`BackBufferCopy<class_backbuffercopy>`, :ref:`CanvasModulate<class_canvasmodulate>`, :ref:`YSort<class_ysort>`, :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:`edit_set_pivot<class_Node2D_edit_set_pivot>` **(** :ref:`Vector2<class_vector2>` pivot **)** |
  16. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_get_angle_to>` **(** :ref:`Vector2<class_vector2>` point **)** const |
  18. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`Vector2<class_vector2>` | :ref:`get_global_pos<class_Node2D_get_global_pos>` **(** **)** const |
  20. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`float<class_float>` | :ref:`get_global_rot<class_Node2D_get_global_rot>` **(** **)** const |
  22. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`float<class_float>` | :ref:`get_global_rotd<class_Node2D_get_global_rotd>` **(** **)** const |
  24. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Vector2<class_vector2>` | :ref:`get_global_scale<class_Node2D_get_global_scale>` **(** **)** const |
  26. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`Vector2<class_vector2>` | :ref:`get_pos<class_Node2D_get_pos>` **(** **)** const |
  28. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Matrix32<class_matrix32>` | :ref:`get_relative_transform_to_parent<class_Node2D_get_relative_transform_to_parent>` **(** :ref:`Object<class_object>` parent **)** const |
  30. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`float<class_float>` | :ref:`get_rot<class_Node2D_get_rot>` **(** **)** const |
  32. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`float<class_float>` | :ref:`get_rotd<class_Node2D_get_rotd>` **(** **)** const |
  34. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Vector2<class_vector2>` | :ref:`get_scale<class_Node2D_get_scale>` **(** **)** const |
  36. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`int<class_int>` | :ref:`get_z<class_Node2D_get_z>` **(** **)** const |
  38. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`global_translate<class_Node2D_global_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  40. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`bool<class_bool>` | :ref:`is_z_relative<class_Node2D_is_z_relative>` **(** **)** const |
  42. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`look_at<class_Node2D_look_at>` **(** :ref:`Vector2<class_vector2>` point **)** |
  44. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`move_local_x<class_Node2D_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  46. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`move_local_y<class_Node2D_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  48. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`rotate<class_Node2D_rotate>` **(** :ref:`float<class_float>` radians **)** |
  50. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`scale<class_Node2D_scale>` **(** :ref:`Vector2<class_vector2>` ratio **)** |
  52. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`set_global_pos<class_Node2D_set_global_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  54. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_global_rot<class_Node2D_set_global_rot>` **(** :ref:`float<class_float>` radians **)** |
  56. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_global_rotd<class_Node2D_set_global_rotd>` **(** :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:`Matrix32<class_matrix32>` xform **)** |
  62. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`set_pos<class_Node2D_set_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  64. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`set_rot<class_Node2D_set_rot>` **(** :ref:`float<class_float>` radians **)** |
  66. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_rotd<class_Node2D_set_rotd>` **(** :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:`Matrix32<class_matrix32>` 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. | void | :ref:`translate<class_Node2D_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  78. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  79. Description
  80. -----------
  81. 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:`Matrix32<class_matrix32>`). A tree of Node2Ds allows complex hierarchies for animation and positioning.
  82. Member Function Description
  83. ---------------------------
  84. .. _class_Node2D_edit_set_pivot:
  85. - void **edit_set_pivot** **(** :ref:`Vector2<class_vector2>` pivot **)**
  86. Set the pivot position of the 2D node to 'pivot' value. This method is implemented only in some nodes that inherit Node2D.
  87. .. _class_Node2D_get_angle_to:
  88. - :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_vector2>` point **)** const
  89. Return the rotation angle in radians needed for the 2d node to point at 'point' position.
  90. .. _class_Node2D_get_global_pos:
  91. - :ref:`Vector2<class_vector2>` **get_global_pos** **(** **)** const
  92. Return the global position of the 2D node.
  93. .. _class_Node2D_get_global_rot:
  94. - :ref:`float<class_float>` **get_global_rot** **(** **)** const
  95. Return the global rotation in radians of the 2D node.
  96. .. _class_Node2D_get_global_rotd:
  97. - :ref:`float<class_float>` **get_global_rotd** **(** **)** const
  98. Return the global rotation in degrees of the 2D node.
  99. .. _class_Node2D_get_global_scale:
  100. - :ref:`Vector2<class_vector2>` **get_global_scale** **(** **)** const
  101. Return the global scale of the 2D node.
  102. .. _class_Node2D_get_pos:
  103. - :ref:`Vector2<class_vector2>` **get_pos** **(** **)** const
  104. Return the position of the 2D node.
  105. .. _class_Node2D_get_relative_transform_to_parent:
  106. - :ref:`Matrix32<class_matrix32>` **get_relative_transform_to_parent** **(** :ref:`Object<class_object>` parent **)** const
  107. Return the transform :ref:`Matrix32<class_matrix32>` calculated relatively to the parent of this 2D node.
  108. .. _class_Node2D_get_rot:
  109. - :ref:`float<class_float>` **get_rot** **(** **)** const
  110. Return the rotation of the 2D node.
  111. .. _class_Node2D_get_rotd:
  112. - :ref:`float<class_float>` **get_rotd** **(** **)** const
  113. .. _class_Node2D_get_scale:
  114. - :ref:`Vector2<class_vector2>` **get_scale** **(** **)** const
  115. Return the scale of the 2D node.
  116. .. _class_Node2D_get_z:
  117. - :ref:`int<class_int>` **get_z** **(** **)** const
  118. Return the Z-index of the 2D node.
  119. .. _class_Node2D_global_translate:
  120. - void **global_translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  121. Apply a global translation of 'offset' to the 2D node, starting from its current global position.
  122. .. _class_Node2D_is_z_relative:
  123. - :ref:`bool<class_bool>` **is_z_relative** **(** **)** const
  124. Return true if the Z-index value of this 2D node is relative to its parent's. Else, return false.
  125. .. _class_Node2D_look_at:
  126. - void **look_at** **(** :ref:`Vector2<class_vector2>` point **)**
  127. Rotate the 2d node so it points at 'point' position.
  128. .. _class_Node2D_move_local_x:
  129. - void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  130. 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.
  131. .. _class_Node2D_move_local_y:
  132. - void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  133. 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.
  134. .. _class_Node2D_rotate:
  135. - void **rotate** **(** :ref:`float<class_float>` radians **)**
  136. Apply a 'radians' rotation to the 2D node, starting from its current rotation.
  137. .. _class_Node2D_scale:
  138. - void **scale** **(** :ref:`Vector2<class_vector2>` ratio **)**
  139. Apply the 'ratio' scale to the 2D node, according to its current scale value.
  140. .. _class_Node2D_set_global_pos:
  141. - void **set_global_pos** **(** :ref:`Vector2<class_vector2>` pos **)**
  142. Set the global position of the 2D node to 'pos'.
  143. .. _class_Node2D_set_global_rot:
  144. - void **set_global_rot** **(** :ref:`float<class_float>` radians **)**
  145. Set the global rotation in radians of the 2D node.
  146. .. _class_Node2D_set_global_rotd:
  147. - void **set_global_rotd** **(** :ref:`float<class_float>` degrees **)**
  148. Set the global rotation in degrees of the 2D node.
  149. .. _class_Node2D_set_global_scale:
  150. - void **set_global_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  151. Set the global scale of the 2D node.
  152. .. _class_Node2D_set_global_transform:
  153. - void **set_global_transform** **(** :ref:`Matrix32<class_matrix32>` xform **)**
  154. Set the global transform :ref:`Matrix32<class_matrix32>` of the 2D node.
  155. .. _class_Node2D_set_pos:
  156. - void **set_pos** **(** :ref:`Vector2<class_vector2>` pos **)**
  157. Set the position of the 2D node.
  158. .. _class_Node2D_set_rot:
  159. - void **set_rot** **(** :ref:`float<class_float>` radians **)**
  160. Set the rotation of the 2D node.
  161. .. _class_Node2D_set_rotd:
  162. - void **set_rotd** **(** :ref:`float<class_float>` degrees **)**
  163. Set the rotation of the 2D node.
  164. .. _class_Node2D_set_scale:
  165. - void **set_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  166. Set the scale of the 2D node.
  167. .. _class_Node2D_set_transform:
  168. - void **set_transform** **(** :ref:`Matrix32<class_matrix32>` xform **)**
  169. Set the local transform :ref:`Matrix32<class_matrix32>` of the 2D node.
  170. .. _class_Node2D_set_z:
  171. - void **set_z** **(** :ref:`int<class_int>` z **)**
  172. Set the Z-index value of the 2D node.
  173. .. _class_Node2D_set_z_as_relative:
  174. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` enable **)**
  175. 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.
  176. .. _class_Node2D_translate:
  177. - void **translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  178. Apply a local translation of 'offset' to the 2D node, starting from its current local position.