Table of Contents

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.

public class Node2D : CanvasItem, IDisposable
Inheritance
Node2D
Implements
Derived
Inherited Members

Constructors

Node2D()

public Node2D()

Properties

GlobalPosition

Global position.

public Vector2 GlobalPosition { get; set; }

Property Value

Vector2

GlobalRotation

Global rotation in radians.

public float GlobalRotation { get; set; }

Property Value

float

GlobalRotationDegrees

Helper property to access GlobalRotation in degrees instead of radians.

public float GlobalRotationDegrees { get; set; }

Property Value

float

GlobalScale

Global scale.

public Vector2 GlobalScale { get; set; }

Property Value

Vector2

GlobalSkew

Global skew in radians.

public float GlobalSkew { get; set; }

Property Value

float

GlobalTransform

Global Transform2D.

public Transform2D GlobalTransform { get; set; }

Property Value

Transform2D

Position

Position, relative to the node's parent.

public Vector2 Position { get; set; }

Property Value

Vector2

Rotation

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

public float Rotation { get; set; }

Property Value

float

RotationDegrees

Helper property to access Rotation in degrees instead of radians.

public float RotationDegrees { get; set; }

Property Value

float

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.

public Vector2 Scale { get; set; }

Property Value

Vector2

Skew

Slants the node.

Note: Skew is X axis only.

public float Skew { get; set; }

Property Value

float

Transform

Local Transform2D.

public Transform2D Transform { get; set; }

Property Value

Transform2D

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.

Illustration of the returned angle.

public float GetAngleTo(Vector2 point)

Parameters

point Vector2

Returns

float

GetRelativeTransformToParent(Node)

Returns the Transform2D relative to this node's parent.

public Transform2D GetRelativeTransformToParent(Node parent)

Parameters

parent Node

Returns

Transform2D

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_name

Name of the method to check for.

Returns

bool

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_name

Name of the signal to check for.

Returns

bool

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_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

LookAt(Vector2)

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

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

delta float
scaled bool

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

delta float
scaled bool

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

Vector2

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

Vector2

Translate(Vector2)

Translates the node by the given offset in local coordinates.

public void Translate(Vector2 offset)

Parameters

offset Vector2