Class Node2D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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 Control inherit from CanvasItem, they share several concepts from the class such as the ZIndex and Visible properties.
public class Node2D : CanvasItem, IDisposable
- Inheritance
-
Node2D
- Implements
- Derived
- Inherited Members
Constructors
Node2D()
public Node2D()
Properties
GlobalPosition
Global position. See also Position.
public Vector2 GlobalPosition { get; set; }
Property Value
GlobalRotation
Global rotation in radians. See also Rotation.
public float GlobalRotation { get; set; }
Property Value
GlobalRotationDegrees
Helper property to access GlobalRotation in degrees instead of radians. See also RotationDegrees.
public float GlobalRotationDegrees { get; set; }
Property Value
GlobalScale
Global scale. See also Scale.
public Vector2 GlobalScale { get; set; }
Property Value
GlobalSkew
Global skew in radians. See also Skew.
public float GlobalSkew { get; set; }
Property Value
GlobalTransform
Global Transform2D. See also Transform.
public Transform2D GlobalTransform { get; set; }
Property Value
Position
Position, relative to the node's parent. See also GlobalPosition.
public Vector2 Position { get; set; }
Property Value
Rotation
Rotation in radians, relative to the node's parent. See also GlobalRotation.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use RotationDegrees.
public float Rotation { get; set; }
Property Value
RotationDegrees
Helper property to access Rotation in degrees instead of radians. See also GlobalRotationDegrees.
public float RotationDegrees { get; set; }
Property Value
Scale
The node's scale, relative to the node's parent. Unscaled value: (1, 1)
. See also GlobalScale.
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.
public Vector2 Scale { get; set; }
Property Value
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 GlobalSkew.
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)
.
public float Skew { get; set; }
Property Value
Transform
The node's Transform2D, relative to the node's parent. See also GlobalTransform.
public Transform2D Transform { get; set; }
Property Value
Methods
ApplyScale(Vector2)
Multiplies the current scale by the ratio
vector.
public void ApplyScale(Vector2 ratio)
Parameters
ratio
Vector2
GetAngleTo(Vector2)
Returns the angle between the node and the point
in radians.
public float GetAngleTo(Vector2 point)
Parameters
point
Vector2
Returns
GetRelativeTransformToParent(Node)
Returns the Transform2D relative to this node's parent.
public Transform2D GetRelativeTransformToParent(Node parent)
Parameters
parent
Node
Returns
GlobalTranslate(Vector2)
Adds the offset
vector to the node's global position.
public void GlobalTranslate(Vector2 offset)
Parameters
offset
Vector2
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
LookAt(Vector2)
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.
public void LookAt(Vector2 point)
Parameters
point
Vector2
MoveLocalX(float, bool)
Applies a local translation on the node's X axis based on the _Process(double)'s delta
. If scaled
is false, normalizes the movement.
public void MoveLocalX(float delta, bool scaled = false)
Parameters
MoveLocalY(float, bool)
Applies a local translation on the node's Y axis based on the _Process(double)'s delta
. If scaled
is false, normalizes the movement.
public void MoveLocalY(float delta, bool scaled = false)
Parameters
Rotate(float)
Applies a rotation to the node, in radians, starting from its current rotation.
public void Rotate(float radians)
Parameters
radians
float
ToGlobal(Vector2)
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.
public Vector2 ToGlobal(Vector2 localPoint)
Parameters
localPoint
Vector2
Returns
ToLocal(Vector2)
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.
public Vector2 ToLocal(Vector2 globalPoint)
Parameters
globalPoint
Vector2
Returns
Translate(Vector2)
Translates the node by the given offset
in local coordinates.
public void Translate(Vector2 offset)
Parameters
offset
Vector2