:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Node2D.xml. .. _class_Node2D: Node2D ====== **Inherits:** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` **Inherited By:** :ref:`AnimatedSprite`, :ref:`AudioStreamPlayer2D`, :ref:`BackBufferCopy`, :ref:`Bone2D`, :ref:`CPUParticles2D`, :ref:`Camera2D`, :ref:`CanvasModulate`, :ref:`CollisionObject2D`, :ref:`CollisionPolygon2D`, :ref:`CollisionShape2D`, :ref:`Joint2D`, :ref:`Light2D`, :ref:`LightOccluder2D`, :ref:`Line2D`, :ref:`Listener2D`, :ref:`MeshInstance2D`, :ref:`MultiMeshInstance2D`, :ref:`Navigation2D`, :ref:`NavigationPolygonInstance`, :ref:`ParallaxLayer`, :ref:`Particles2D`, :ref:`Path2D`, :ref:`PathFollow2D`, :ref:`Polygon2D`, :ref:`Position2D`, :ref:`RayCast2D`, :ref:`RemoteTransform2D`, :ref:`ShapeCast2D`, :ref:`Skeleton2D`, :ref:`Sprite`, :ref:`TileMap`, :ref:`TouchScreenButton`, :ref:`VisibilityNotifier2D`, :ref:`YSort` A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index. 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. Tutorials --------- - :doc:`Custom drawing in 2D <../tutorials/2d/custom_drawing_in_2d>` - `All 2D Demos `__ Properties ---------- +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`global_position` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`global_rotation` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`global_rotation_degrees` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`global_scale` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Transform2D` | :ref:`global_transform` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`position` | ``Vector2( 0, 0 )`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`rotation` | ``0.0`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`rotation_degrees` | ``0.0`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`scale` | ``Vector2( 1, 1 )`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`Transform2D` | :ref:`transform` | | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`z_as_relative` | ``true`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ | :ref:`int` | :ref:`z_index` | ``0`` | +---------------------------------------+-------------------------------------------------------------------------------+---------------------+ Methods ------- +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`apply_scale` **(** :ref:`Vector2` ratio **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_angle_to` **(** :ref:`Vector2` point **)** |const| | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Transform2D` | :ref:`get_relative_transform_to_parent` **(** :ref:`Node` parent **)** |const| | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`global_translate` **(** :ref:`Vector2` offset **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`look_at` **(** :ref:`Vector2` point **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`move_local_x` **(** :ref:`float` delta, :ref:`bool` scaled=false **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`move_local_y` **(** :ref:`float` delta, :ref:`bool` scaled=false **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`rotate` **(** :ref:`float` radians **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`to_global` **(** :ref:`Vector2` local_point **)** |const| | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`to_local` **(** :ref:`Vector2` global_point **)** |const| | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`translate` **(** :ref:`Vector2` offset **)** | +---------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ Property Descriptions --------------------- .. _class_Node2D_property_global_position: - :ref:`Vector2` **global_position** +----------+----------------------------+ | *Setter* | set_global_position(value) | +----------+----------------------------+ | *Getter* | get_global_position() | +----------+----------------------------+ Global position. ---- .. _class_Node2D_property_global_rotation: - :ref:`float` **global_rotation** +----------+----------------------------+ | *Setter* | set_global_rotation(value) | +----------+----------------------------+ | *Getter* | get_global_rotation() | +----------+----------------------------+ Global rotation in radians. ---- .. _class_Node2D_property_global_rotation_degrees: - :ref:`float` **global_rotation_degrees** +----------+------------------------------------+ | *Setter* | set_global_rotation_degrees(value) | +----------+------------------------------------+ | *Getter* | get_global_rotation_degrees() | +----------+------------------------------------+ Global rotation in degrees. ---- .. _class_Node2D_property_global_scale: - :ref:`Vector2` **global_scale** +----------+-------------------------+ | *Setter* | set_global_scale(value) | +----------+-------------------------+ | *Getter* | get_global_scale() | +----------+-------------------------+ Global scale. ---- .. _class_Node2D_property_global_transform: - :ref:`Transform2D` **global_transform** +----------+-----------------------------+ | *Setter* | set_global_transform(value) | +----------+-----------------------------+ | *Getter* | get_global_transform() | +----------+-----------------------------+ Global :ref:`Transform2D`. ---- .. _class_Node2D_property_position: - :ref:`Vector2` **position** +-----------+---------------------+ | *Default* | ``Vector2( 0, 0 )`` | +-----------+---------------------+ | *Setter* | set_position(value) | +-----------+---------------------+ | *Getter* | get_position() | +-----------+---------------------+ Position, relative to the node's parent. ---- .. _class_Node2D_property_rotation: - :ref:`float` **rotation** +-----------+---------------------+ | *Default* | ``0.0`` | +-----------+---------------------+ | *Setter* | set_rotation(value) | +-----------+---------------------+ | *Getter* | get_rotation() | +-----------+---------------------+ Rotation in radians, relative to the node's parent. ---- .. _class_Node2D_property_rotation_degrees: - :ref:`float` **rotation_degrees** +-----------+-----------------------------+ | *Default* | ``0.0`` | +-----------+-----------------------------+ | *Setter* | set_rotation_degrees(value) | +-----------+-----------------------------+ | *Getter* | get_rotation_degrees() | +-----------+-----------------------------+ Rotation in degrees, relative to the node's parent. ---- .. _class_Node2D_property_scale: - :ref:`Vector2` **scale** +-----------+---------------------+ | *Default* | ``Vector2( 1, 1 )`` | +-----------+---------------------+ | *Setter* | set_scale(value) | +-----------+---------------------+ | *Getter* | get_scale() | +-----------+---------------------+ The node's scale. Unscaled value: ``(1, 1)``. \ **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. ---- .. _class_Node2D_property_transform: - :ref:`Transform2D` **transform** +----------+----------------------+ | *Setter* | set_transform(value) | +----------+----------------------+ | *Getter* | get_transform() | +----------+----------------------+ Local :ref:`Transform2D`. ---- .. _class_Node2D_property_z_as_relative: - :ref:`bool` **z_as_relative** +-----------+--------------------------+ | *Default* | ``true`` | +-----------+--------------------------+ | *Setter* | set_z_as_relative(value) | +-----------+--------------------------+ | *Getter* | is_z_relative() | +-----------+--------------------------+ If ``true``, the node's Z index is 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. ---- .. _class_Node2D_property_z_index: - :ref:`int` **z_index** +-----------+--------------------+ | *Default* | ``0`` | +-----------+--------------------+ | *Setter* | set_z_index(value) | +-----------+--------------------+ | *Getter* | get_z_index() | +-----------+--------------------+ Z index. Controls the order in which the nodes render. A node with a higher Z index will display in front of others. Must be between :ref:`VisualServer.CANVAS_ITEM_Z_MIN` and :ref:`VisualServer.CANVAS_ITEM_Z_MAX` (inclusive). Method Descriptions ------------------- .. _class_Node2D_method_apply_scale: - void **apply_scale** **(** :ref:`Vector2` ratio **)** Multiplies the current scale by the ``ratio`` vector. ---- .. _class_Node2D_method_get_angle_to: - :ref:`float` **get_angle_to** **(** :ref:`Vector2` point **)** |const| Returns the angle between the node and the ``point`` in radians. \ `Illustration of the returned angle. `__ ---- .. _class_Node2D_method_get_relative_transform_to_parent: - :ref:`Transform2D` **get_relative_transform_to_parent** **(** :ref:`Node` parent **)** |const| Returns the :ref:`Transform2D` relative to this node's parent. ---- .. _class_Node2D_method_global_translate: - void **global_translate** **(** :ref:`Vector2` offset **)** Adds the ``offset`` vector to the node's global position. ---- .. _class_Node2D_method_look_at: - void **look_at** **(** :ref:`Vector2` point **)** Rotates the node so it points towards the ``point``, which is expected to use global coordinates. ---- .. _class_Node2D_method_move_local_x: - void **move_local_x** **(** :ref:`float` delta, :ref:`bool` scaled=false **)** 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. ---- .. _class_Node2D_method_move_local_y: - void **move_local_y** **(** :ref:`float` delta, :ref:`bool` scaled=false **)** 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. ---- .. _class_Node2D_method_rotate: - void **rotate** **(** :ref:`float` radians **)** Applies a rotation to the node, in radians, starting from its current rotation. ---- .. _class_Node2D_method_to_global: - :ref:`Vector2` **to_global** **(** :ref:`Vector2` local_point **)** |const| 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. ---- .. _class_Node2D_method_to_local: - :ref:`Vector2` **to_local** **(** :ref:`Vector2` global_point **)** |const| 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. ---- .. _class_Node2D_method_translate: - void **translate** **(** :ref:`Vector2` offset **)** 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.)` .. |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.)`