Skip to content

Latest commit

 

History

History
461 lines (269 loc) · 20.7 KB

class_node2d.rst

File metadata and controls

461 lines (269 loc) · 20.7 KB
github_url:hide

Node2D

Inherits: :ref:`CanvasItem<class_CanvasItem>` < :ref:`Node<class_Node>` < :ref:`Object<class_Object>`

Inherited By: :ref:`AnimatedSprite2D<class_AnimatedSprite2D>`, :ref:`AudioListener2D<class_AudioListener2D>`, :ref:`AudioStreamPlayer2D<class_AudioStreamPlayer2D>`, :ref:`BackBufferCopy<class_BackBufferCopy>`, :ref:`Bone2D<class_Bone2D>`, :ref:`Camera2D<class_Camera2D>`, :ref:`CanvasGroup<class_CanvasGroup>`, :ref:`CanvasModulate<class_CanvasModulate>`, :ref:`CollisionObject2D<class_CollisionObject2D>`, :ref:`CollisionPolygon2D<class_CollisionPolygon2D>`, :ref:`CollisionShape2D<class_CollisionShape2D>`, :ref:`CPUParticles2D<class_CPUParticles2D>`, :ref:`GPUParticles2D<class_GPUParticles2D>`, :ref:`Joint2D<class_Joint2D>`, :ref:`Light2D<class_Light2D>`, :ref:`LightOccluder2D<class_LightOccluder2D>`, :ref:`Line2D<class_Line2D>`, :ref:`Marker2D<class_Marker2D>`, :ref:`MeshInstance2D<class_MeshInstance2D>`, :ref:`MultiMeshInstance2D<class_MultiMeshInstance2D>`, :ref:`NavigationLink2D<class_NavigationLink2D>`, :ref:`NavigationObstacle2D<class_NavigationObstacle2D>`, :ref:`NavigationRegion2D<class_NavigationRegion2D>`, :ref:`ParallaxLayer<class_ParallaxLayer>`, :ref:`Path2D<class_Path2D>`, :ref:`PathFollow2D<class_PathFollow2D>`, :ref:`Polygon2D<class_Polygon2D>`, :ref:`RayCast2D<class_RayCast2D>`, :ref:`RemoteTransform2D<class_RemoteTransform2D>`, :ref:`ShapeCast2D<class_ShapeCast2D>`, :ref:`Skeleton2D<class_Skeleton2D>`, :ref:`Sprite2D<class_Sprite2D>`, :ref:`TileMap<class_TileMap>`, :ref:`TouchScreenButton<class_TouchScreenButton>`, :ref:`VisibleOnScreenNotifier2D<class_VisibleOnScreenNotifier2D>`

A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.

.. 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.

.. rst-class:: classref-introduction-group

Tutorials

.. rst-class:: classref-reftable-group

Properties

:ref:`Vector2<class_Vector2>` :ref:`global_position<class_Node2D_property_global_position>`  
:ref:`float<class_float>` :ref:`global_rotation<class_Node2D_property_global_rotation>`  
:ref:`float<class_float>` :ref:`global_rotation_degrees<class_Node2D_property_global_rotation_degrees>`  
:ref:`Vector2<class_Vector2>` :ref:`global_scale<class_Node2D_property_global_scale>`  
:ref:`float<class_float>` :ref:`global_skew<class_Node2D_property_global_skew>`  
:ref:`Transform2D<class_Transform2D>` :ref:`global_transform<class_Node2D_property_global_transform>`  
:ref:`Vector2<class_Vector2>` :ref:`position<class_Node2D_property_position>` Vector2(0, 0)
:ref:`float<class_float>` :ref:`rotation<class_Node2D_property_rotation>` 0.0
:ref:`float<class_float>` :ref:`rotation_degrees<class_Node2D_property_rotation_degrees>`  
:ref:`Vector2<class_Vector2>` :ref:`scale<class_Node2D_property_scale>` Vector2(1, 1)
:ref:`float<class_float>` :ref:`skew<class_Node2D_property_skew>` 0.0
:ref:`Transform2D<class_Transform2D>` :ref:`transform<class_Node2D_property_transform>`  
.. rst-class:: classref-reftable-group

Methods

void :ref:`apply_scale<class_Node2D_method_apply_scale>` ( :ref:`Vector2<class_Vector2>` ratio )
:ref:`float<class_float>` :ref:`get_angle_to<class_Node2D_method_get_angle_to>` ( :ref:`Vector2<class_Vector2>` point ) |const|
:ref:`Transform2D<class_Transform2D>` :ref:`get_relative_transform_to_parent<class_Node2D_method_get_relative_transform_to_parent>` ( :ref:`Node<class_Node>` parent ) |const|
void :ref:`global_translate<class_Node2D_method_global_translate>` ( :ref:`Vector2<class_Vector2>` offset )
void :ref:`look_at<class_Node2D_method_look_at>` ( :ref:`Vector2<class_Vector2>` point )
void :ref:`move_local_x<class_Node2D_method_move_local_x>` ( :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false )
void :ref:`move_local_y<class_Node2D_method_move_local_y>` ( :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false )
void :ref:`rotate<class_Node2D_method_rotate>` ( :ref:`float<class_float>` radians )
:ref:`Vector2<class_Vector2>` :ref:`to_global<class_Node2D_method_to_global>` ( :ref:`Vector2<class_Vector2>` local_point ) |const|
:ref:`Vector2<class_Vector2>` :ref:`to_local<class_Node2D_method_to_local>` ( :ref:`Vector2<class_Vector2>` global_point ) |const|
void :ref:`translate<class_Node2D_method_translate>` ( :ref:`Vector2<class_Vector2>` offset )
.. rst-class:: classref-section-separator


.. rst-class:: classref-descriptions-group

Property Descriptions

.. rst-class:: classref-property

:ref:`Vector2<class_Vector2>` global_position

.. rst-class:: classref-property-setget

Global position.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` global_rotation

.. rst-class:: classref-property-setget

Global rotation in radians.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` global_rotation_degrees

.. rst-class:: classref-property-setget

Helper property to access :ref:`global_rotation<class_Node2D_property_global_rotation>` in degrees instead of radians.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Vector2<class_Vector2>` global_scale

.. rst-class:: classref-property-setget

Global scale.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` global_skew

.. rst-class:: classref-property-setget

Global skew in radians.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Transform2D<class_Transform2D>` global_transform

.. rst-class:: classref-property-setget

Global :ref:`Transform2D<class_Transform2D>`.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Vector2<class_Vector2>` position = Vector2(0, 0)

.. rst-class:: classref-property-setget

Position, relative to the node's parent.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` rotation = 0.0

.. rst-class:: classref-property-setget

Rotation in radians, relative to the node's parent.

Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use :ref:`rotation_degrees<class_Node2D_property_rotation_degrees>`.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` rotation_degrees

.. rst-class:: classref-property-setget

Helper property to access :ref:`rotation<class_Node2D_property_rotation>` in degrees instead of radians.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Vector2<class_Vector2>` scale = Vector2(1, 1)

.. rst-class:: classref-property-setget

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.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`float<class_float>` skew = 0.0

.. rst-class:: classref-property-setget

Slants the node.

Note: Skew is X axis only.

.. rst-class:: classref-item-separator


.. rst-class:: classref-property

:ref:`Transform2D<class_Transform2D>` transform

.. rst-class:: classref-property-setget

Local :ref:`Transform2D<class_Transform2D>`.

.. rst-class:: classref-section-separator


.. rst-class:: classref-descriptions-group

Method Descriptions

.. rst-class:: classref-method

void apply_scale ( :ref:`Vector2<class_Vector2>` ratio )

Multiplies the current scale by the ratio vector.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`float<class_float>` get_angle_to ( :ref:`Vector2<class_Vector2>` point ) |const|

Returns the angle between the node and the point in radians.

Illustration of the returned angle.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`Transform2D<class_Transform2D>` get_relative_transform_to_parent ( :ref:`Node<class_Node>` parent ) |const|

Returns the :ref:`Transform2D<class_Transform2D>` relative to this node's parent.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void global_translate ( :ref:`Vector2<class_Vector2>` offset )

Adds the offset vector to the node's global position.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void look_at ( :ref:`Vector2<class_Vector2>` point )

Rotates the node so it points towards the point, which is expected to use global coordinates.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void move_local_x ( :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false )

Applies a local translation on the node's X axis based on the :ref:`Node._process<class_Node_method__process>`'s delta. If scaled is false, normalizes the movement.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void move_local_y ( :ref:`float<class_float>` delta, :ref:`bool<class_bool>` scaled=false )

Applies a local translation on the node's Y axis based on the :ref:`Node._process<class_Node_method__process>`'s delta. If scaled is false, normalizes the movement.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void rotate ( :ref:`float<class_float>` radians )

Applies a rotation to the node, in radians, starting from its current rotation.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`Vector2<class_Vector2>` to_global ( :ref:`Vector2<class_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.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

:ref:`Vector2<class_Vector2>` to_local ( :ref:`Vector2<class_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.

.. rst-class:: classref-item-separator


.. rst-class:: classref-method

void translate ( :ref:`Vector2<class_Vector2>` offset )

Translates the node by the given offset in local coordinates.