class_node2d.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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:`set_pos<class_Node2D_set_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  16. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  17. | void | :ref:`set_rot<class_Node2D_set_rot>` **(** :ref:`float<class_float>` radians **)** |
  18. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  19. | void | :ref:`set_rotd<class_Node2D_set_rotd>` **(** :ref:`float<class_float>` degrees **)** |
  20. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  21. | void | :ref:`set_scale<class_Node2D_set_scale>` **(** :ref:`Vector2<class_vector2>` scale **)** |
  22. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Vector2<class_vector2>` | :ref:`get_pos<class_Node2D_get_pos>` **(** **)** const |
  24. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`float<class_float>` | :ref:`get_rot<class_Node2D_get_rot>` **(** **)** const |
  26. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`get_rotd<class_Node2D_get_rotd>` **(** **)** const |
  28. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Vector2<class_vector2>` | :ref:`get_scale<class_Node2D_get_scale>` **(** **)** const |
  30. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`rotate<class_Node2D_rotate>` **(** :ref:`float<class_float>` radians **)** |
  32. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`move_local_x<class_Node2D_move_local_x>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  34. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`move_local_y<class_Node2D_move_local_y>` **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)** |
  36. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`translate<class_Node2D_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  38. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`global_translate<class_Node2D_global_translate>` **(** :ref:`Vector2<class_vector2>` offset **)** |
  40. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`scale<class_Node2D_scale>` **(** :ref:`Vector2<class_vector2>` ratio **)** |
  42. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`set_global_pos<class_Node2D_set_global_pos>` **(** :ref:`Vector2<class_vector2>` pos **)** |
  44. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Vector2<class_vector2>` | :ref:`get_global_pos<class_Node2D_get_global_pos>` **(** **)** const |
  46. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  47. | void | :ref:`set_transform<class_Node2D_set_transform>` **(** :ref:`Matrix32<class_matrix32>` xform **)** |
  48. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`set_global_transform<class_Node2D_set_global_transform>` **(** :ref:`Matrix32<class_matrix32>` xform **)** |
  50. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`look_at<class_Node2D_look_at>` **(** :ref:`Vector2<class_vector2>` point **)** |
  52. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`get_angle_to<class_Node2D_get_angle_to>` **(** :ref:`Vector2<class_vector2>` point **)** const |
  54. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`set_z<class_Node2D_set_z>` **(** :ref:`int<class_int>` z **)** |
  56. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_z<class_Node2D_get_z>` **(** **)** const |
  58. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_z_as_relative<class_Node2D_set_z_as_relative>` **(** :ref:`bool<class_bool>` enable **)** |
  60. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`is_z_relative<class_Node2D_is_z_relative>` **(** **)** const |
  62. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`edit_set_pivot<class_Node2D_edit_set_pivot>` **(** :ref:`Vector2<class_vector2>` pivot **)** |
  64. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Matrix32<class_matrix32>` | :ref:`get_relative_transform_to_parent<class_Node2D_get_relative_transform_to_parent>` **(** :ref:`Object<class_object>` parent **)** const |
  66. +----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
  67. Description
  68. -----------
  69. 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.
  70. Member Function Description
  71. ---------------------------
  72. .. _class_Node2D_set_pos:
  73. - void **set_pos** **(** :ref:`Vector2<class_vector2>` pos **)**
  74. Set the position of the 2D node.
  75. .. _class_Node2D_set_rot:
  76. - void **set_rot** **(** :ref:`float<class_float>` radians **)**
  77. Set the rotation of the 2D node.
  78. .. _class_Node2D_set_rotd:
  79. - void **set_rotd** **(** :ref:`float<class_float>` degrees **)**
  80. Set the rotation of the 2D node.
  81. .. _class_Node2D_set_scale:
  82. - void **set_scale** **(** :ref:`Vector2<class_vector2>` scale **)**
  83. Set the scale of the 2D node.
  84. .. _class_Node2D_get_pos:
  85. - :ref:`Vector2<class_vector2>` **get_pos** **(** **)** const
  86. Return the position of the 2D node.
  87. .. _class_Node2D_get_rot:
  88. - :ref:`float<class_float>` **get_rot** **(** **)** const
  89. Return the rotation of the 2D node.
  90. .. _class_Node2D_get_rotd:
  91. - :ref:`float<class_float>` **get_rotd** **(** **)** const
  92. .. _class_Node2D_get_scale:
  93. - :ref:`Vector2<class_vector2>` **get_scale** **(** **)** const
  94. Return the scale of the 2D node.
  95. .. _class_Node2D_rotate:
  96. - void **rotate** **(** :ref:`float<class_float>` radians **)**
  97. Apply a 'radians' rotation to the 2D node, starting from its current rotation.
  98. .. _class_Node2D_move_local_x:
  99. - void **move_local_x** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  100. 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.
  101. .. _class_Node2D_move_local_y:
  102. - void **move_local_y** **(** :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false **)**
  103. 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.
  104. .. _class_Node2D_translate:
  105. - void **translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  106. Apply a local translation of 'offset' to the 2D node, starting from its current local position.
  107. .. _class_Node2D_global_translate:
  108. - void **global_translate** **(** :ref:`Vector2<class_vector2>` offset **)**
  109. Apply a global translation of 'offset' to the 2D node, starting from its current global position.
  110. .. _class_Node2D_scale:
  111. - void **scale** **(** :ref:`Vector2<class_vector2>` ratio **)**
  112. Apply the 'ratio' scale to the 2D node, according to its current scale value.
  113. .. _class_Node2D_set_global_pos:
  114. - void **set_global_pos** **(** :ref:`Vector2<class_vector2>` pos **)**
  115. Set the global position of the 2D node to 'pos'.
  116. .. _class_Node2D_get_global_pos:
  117. - :ref:`Vector2<class_vector2>` **get_global_pos** **(** **)** const
  118. Return the global position of the 2D node.
  119. .. _class_Node2D_set_transform:
  120. - void **set_transform** **(** :ref:`Matrix32<class_matrix32>` xform **)**
  121. Set the local transform :ref:`Matrix32<class_matrix32>` of the 2D node.
  122. .. _class_Node2D_set_global_transform:
  123. - void **set_global_transform** **(** :ref:`Matrix32<class_matrix32>` xform **)**
  124. Set the global transform :ref:`Matrix32<class_matrix32>` of the 2D node.
  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_get_angle_to:
  129. - :ref:`float<class_float>` **get_angle_to** **(** :ref:`Vector2<class_vector2>` point **)** const
  130. Return the rotation angle in radians needed for the 2d node to point at 'point' position.
  131. .. _class_Node2D_set_z:
  132. - void **set_z** **(** :ref:`int<class_int>` z **)**
  133. Set the Z-index value of the 2D node.
  134. .. _class_Node2D_get_z:
  135. - :ref:`int<class_int>` **get_z** **(** **)** const
  136. Return the Z-index of the 2D node.
  137. .. _class_Node2D_set_z_as_relative:
  138. - void **set_z_as_relative** **(** :ref:`bool<class_bool>` enable **)**
  139. 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.
  140. .. _class_Node2D_is_z_relative:
  141. - :ref:`bool<class_bool>` **is_z_relative** **(** **)** const
  142. Return true if the Z-index value of this 2D node is relative to its parent's. Else, return false.
  143. .. _class_Node2D_edit_set_pivot:
  144. - void **edit_set_pivot** **(** :ref:`Vector2<class_vector2>` pivot **)**
  145. Set the pivot position of the 2D node to 'pivot' value. This method is implemented only in some nodes that inherit Node2D.
  146. .. _class_Node2D_get_relative_transform_to_parent:
  147. - :ref:`Matrix32<class_matrix32>` **get_relative_transform_to_parent** **(** :ref:`Object<class_object>` parent **)** const
  148. Return the transform :ref:`Matrix32<class_matrix32>` calculated relatively to the parent of this 2D node.