:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Node2D.xml. .. _class_Node2D: Node2D ====== **Inherits:** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` **Inherited By:** :ref:`AnimatedSprite2D`, :ref:`AudioListener2D`, :ref:`AudioStreamPlayer2D`, :ref:`BackBufferCopy`, :ref:`Bone2D`, :ref:`Camera2D`, :ref:`CanvasGroup`, :ref:`CanvasModulate`, :ref:`CollisionObject2D`, :ref:`CollisionPolygon2D`, :ref:`CollisionShape2D`, :ref:`CPUParticles2D`, :ref:`GPUParticles2D`, :ref:`Joint2D`, :ref:`Light2D`, :ref:`LightOccluder2D`, :ref:`Line2D`, :ref:`Marker2D`, :ref:`MeshInstance2D`, :ref:`MultiMeshInstance2D`, :ref:`NavigationLink2D`, :ref:`NavigationObstacle2D`, :ref:`NavigationRegion2D`, :ref:`Parallax2D`, :ref:`ParallaxLayer`, :ref:`Path2D`, :ref:`PathFollow2D`, :ref:`Polygon2D`, :ref:`RayCast2D`, :ref:`RemoteTransform2D`, :ref:`ShapeCast2D`, :ref:`Skeleton2D`, :ref:`Sprite2D`, :ref:`TileMap`, :ref:`TileMapLayer`, :ref:`TouchScreenButton`, :ref:`VisibleOnScreenNotifier2D` A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and skew. .. rst-class:: classref-introduction-group Description ----------- A 2D game object, with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control of the node's render order. \ **Note:** Since both **Node2D** and :ref:`Control` inherit from :ref:`CanvasItem`, they share several concepts from the class such as the :ref:`CanvasItem.z_index` and :ref:`CanvasItem.visible` properties. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Custom drawing in 2D <../tutorials/2d/custom_drawing_in_2d>` - `All 2D Demos `__ .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`global_position` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`global_rotation` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`global_rotation_degrees` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`global_scale` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`global_skew` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Transform2D` | :ref:`global_transform` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`position` | ``Vector2(0, 0)`` | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`rotation` | ``0.0`` | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`rotation_degrees` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Vector2` | :ref:`scale` | ``Vector2(1, 1)`` | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`float` | :ref:`skew` | ``0.0`` | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ | :ref:`Transform2D` | :ref:`transform` | | +---------------------------------------+-------------------------------------------------------------------------------+-------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`apply_scale`\ (\ ratio\: :ref:`Vector2`\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_angle_to`\ (\ point\: :ref:`Vector2`\ ) |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Transform2D` | :ref:`get_relative_transform_to_parent`\ (\ parent\: :ref:`Node`\ ) |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`global_translate`\ (\ offset\: :ref:`Vector2`\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`look_at`\ (\ point\: :ref:`Vector2`\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`move_local_x`\ (\ delta\: :ref:`float`, scaled\: :ref:`bool` = false\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`move_local_y`\ (\ delta\: :ref:`float`, scaled\: :ref:`bool` = false\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`rotate`\ (\ radians\: :ref:`float`\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`to_global`\ (\ local_point\: :ref:`Vector2`\ ) |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`to_local`\ (\ global_point\: :ref:`Vector2`\ ) |const| | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`translate`\ (\ offset\: :ref:`Vector2`\ ) | +---------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_Node2D_property_global_position: .. rst-class:: classref-property :ref:`Vector2` **global_position** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_position**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_global_position**\ (\ ) Global position. See also :ref:`position`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_global_rotation: .. rst-class:: classref-property :ref:`float` **global_rotation** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_rotation**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_global_rotation**\ (\ ) Global rotation in radians. See also :ref:`rotation`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_global_rotation_degrees: .. rst-class:: classref-property :ref:`float` **global_rotation_degrees** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_rotation_degrees**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_global_rotation_degrees**\ (\ ) Helper property to access :ref:`global_rotation` in degrees instead of radians. See also :ref:`rotation_degrees`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_global_scale: .. rst-class:: classref-property :ref:`Vector2` **global_scale** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_scale**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_global_scale**\ (\ ) Global scale. See also :ref:`scale`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_global_skew: .. rst-class:: classref-property :ref:`float` **global_skew** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_skew**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_global_skew**\ (\ ) Global skew in radians. See also :ref:`skew`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_global_transform: .. rst-class:: classref-property :ref:`Transform2D` **global_transform** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_global_transform**\ (\ value\: :ref:`Transform2D`\ ) - :ref:`Transform2D` **get_global_transform**\ (\ ) Global :ref:`Transform2D`. See also :ref:`transform`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_position: .. rst-class:: classref-property :ref:`Vector2` **position** = ``Vector2(0, 0)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_position**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_position**\ (\ ) Position, relative to the node's parent. See also :ref:`global_position`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_rotation: .. rst-class:: classref-property :ref:`float` **rotation** = ``0.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_rotation**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_rotation**\ (\ ) Rotation in radians, relative to the node's parent. See also :ref:`global_rotation`. \ **Note:** This property is edited in the inspector in degrees. If you want to use degrees in a script, use :ref:`rotation_degrees`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_rotation_degrees: .. rst-class:: classref-property :ref:`float` **rotation_degrees** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_rotation_degrees**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_rotation_degrees**\ (\ ) Helper property to access :ref:`rotation` in degrees instead of radians. See also :ref:`global_rotation_degrees`. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_scale: .. rst-class:: classref-property :ref:`Vector2` **scale** = ``Vector2(1, 1)`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_scale**\ (\ value\: :ref:`Vector2`\ ) - :ref:`Vector2` **get_scale**\ (\ ) The node's scale, relative to the node's parent. Unscaled value: ``(1, 1)``. See also :ref:`global_scale`. \ **Note:** Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_skew: .. rst-class:: classref-property :ref:`float` **skew** = ``0.0`` :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_skew**\ (\ value\: :ref:`float`\ ) - :ref:`float` **get_skew**\ (\ ) If set to a non-zero value, slants the node in one direction or another. This can be used for pseudo-3D effects. See also :ref:`global_skew`. \ **Note:** Skew is performed on the X axis only, and *between* rotation and scaling. \ **Note:** This property is edited in the inspector in degrees. If you want to use degrees in a script, use ``skew = deg_to_rad(value_in_degrees)``. .. rst-class:: classref-item-separator ---- .. _class_Node2D_property_transform: .. rst-class:: classref-property :ref:`Transform2D` **transform** :ref:`🔗` .. rst-class:: classref-property-setget - |void| **set_transform**\ (\ value\: :ref:`Transform2D`\ ) - :ref:`Transform2D` **get_transform**\ (\ ) The node's :ref:`Transform2D`, relative to the node's parent. See also :ref:`global_transform`. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Node2D_method_apply_scale: .. rst-class:: classref-method |void| **apply_scale**\ (\ ratio\: :ref:`Vector2`\ ) :ref:`🔗` Multiplies the current scale by the ``ratio`` vector. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_get_angle_to: .. rst-class:: classref-method :ref:`float` **get_angle_to**\ (\ point\: :ref:`Vector2`\ ) |const| :ref:`🔗` Returns the angle between the node and the ``point`` in radians. \ `Illustration of the returned angle. `__ .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_get_relative_transform_to_parent: .. rst-class:: classref-method :ref:`Transform2D` **get_relative_transform_to_parent**\ (\ parent\: :ref:`Node`\ ) |const| :ref:`🔗` Returns the :ref:`Transform2D` relative to this node's parent. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_global_translate: .. rst-class:: classref-method |void| **global_translate**\ (\ offset\: :ref:`Vector2`\ ) :ref:`🔗` Adds the ``offset`` vector to the node's global position. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_look_at: .. rst-class:: classref-method |void| **look_at**\ (\ point\: :ref:`Vector2`\ ) :ref:`🔗` Rotates the node so that its local +X axis points towards the ``point``, which is expected to use global coordinates. \ ``point`` should not be the same as the node's position, otherwise the node always looks to the right. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_move_local_x: .. rst-class:: classref-method |void| **move_local_x**\ (\ delta\: :ref:`float`, scaled\: :ref:`bool` = false\ ) :ref:`🔗` Applies a local translation on the node's X axis based on the :ref:`Node._process()`'s ``delta``. If ``scaled`` is ``false``, normalizes the movement. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_move_local_y: .. rst-class:: classref-method |void| **move_local_y**\ (\ delta\: :ref:`float`, scaled\: :ref:`bool` = false\ ) :ref:`🔗` Applies a local translation on the node's Y axis based on the :ref:`Node._process()`'s ``delta``. If ``scaled`` is ``false``, normalizes the movement. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_rotate: .. rst-class:: classref-method |void| **rotate**\ (\ radians\: :ref:`float`\ ) :ref:`🔗` Applies a rotation to the node, in radians, starting from its current rotation. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_to_global: .. rst-class:: classref-method :ref:`Vector2` **to_global**\ (\ local_point\: :ref:`Vector2`\ ) |const| :ref:`🔗` Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to the **Node2D** it is called on. e.g. Applying this method to the positions of child nodes will correctly transform their positions into the global coordinate space, but applying it to a node's own position will give an incorrect result, as it will incorporate the node's own transformation into its global position. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_to_local: .. rst-class:: classref-method :ref:`Vector2` **to_local**\ (\ global_point\: :ref:`Vector2`\ ) |const| :ref:`🔗` Transforms the provided global position into a position in local coordinate space. The output will be local relative to the **Node2D** it is called on. e.g. It is appropriate for determining the positions of child nodes, but it is not appropriate for determining its own position relative to its parent. .. rst-class:: classref-item-separator ---- .. _class_Node2D_method_translate: .. rst-class:: classref-method |void| **translate**\ (\ offset\: :ref:`Vector2`\ ) :ref:`🔗` Translates the node by the given ``offset`` in local coordinates. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`