Table of Contents

Class Node2D

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

Inheritance
Node2D
Derived

Remarks

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 z_index and visible properties.

See Also

Properties

global_position

Global position. See also position.

var global_position : Vector2

Property Value

Vector2

Remarks

global_rotation

Global rotation in radians. See also rotation.

var global_rotation : float

Property Value

float

Remarks

  • void set_global_rotation(float value)
  • float get_global_rotation

global_rotation_degrees

Helper property to access global_rotation in degrees instead of radians. See also rotation_degrees.

var global_rotation_degrees : float

Property Value

float

Remarks

  • void set_global_rotation_degrees(float value)
  • float get_global_rotation_degrees

global_scale

Global scale. See also scale.

var global_scale : Vector2

Property Value

Vector2

Remarks

global_skew

Global skew in radians. See also skew.

var global_skew : float

Property Value

float

Remarks

  • void set_global_skew(float value)
  • float get_global_skew

global_transform

Global Transform2D. See also transform.

var global_transform : Transform2D

Property Value

Transform2D

Remarks

position

Position, relative to the node's parent. See also global_position.

var position : Vector2 = Vector2(0, 0)

Property Value

Vector2

Remarks

rotation

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

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

var rotation : float = 0.0

Property Value

float

Remarks

  • void set_rotation(float value)
  • float get_rotation

rotation_degrees

Helper property to access rotation in degrees instead of radians. See also global_rotation_degrees.

var rotation_degrees : float

Property Value

float

Remarks

  • void set_rotation_degrees(float value)
  • float get_rotation_degrees

scale

The node's scale, relative to the node's parent. Unscaled value: (1, 1). See also 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.

var scale : Vector2 = Vector2(1, 1)

Property Value

Vector2

Remarks

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

var skew : float = 0.0

Property Value

float

Remarks

transform

The node's Transform2D, relative to the node's parent. See also global_transform.

var transform : Transform2D

Property Value

Transform2D

Remarks

Methods

apply_scale(Vector2)

Multiplies the current scale by the ratio vector.

void apply_scale(Vector2 ratio)

Parameters

ratio Vector2

get_angle_to(Vector2)

Qualifiers: const

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

\ Illustration of the returned angle.

float get_angle_to(Vector2 point)

Parameters

point Vector2

get_relative_transform_to_parent(Node)

Qualifiers: const

Returns the Transform2D relative to this node's parent.

Transform2D get_relative_transform_to_parent(Node parent)

Parameters

parent Node

global_translate(Vector2)

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

void global_translate(Vector2 offset)

Parameters

offset Vector2

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

void look_at(Vector2 point)

Parameters

point Vector2

move_local_x(float, bool)

Applies a local translation on the node's X axis based on the Node._process's delta. If scaled is false, normalizes the movement.

void move_local_x(float delta, bool scaled)

Parameters

delta float
scaled bool

move_local_y(float, bool)

Applies a local translation on the node's Y axis based on the Node._process's delta. If scaled is false, normalizes the movement.

void move_local_y(float delta, bool scaled)

Parameters

delta float
scaled bool

rotate(float)

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

void rotate(float radians)

Parameters

radians float

to_global(Vector2)

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

Vector2 to_global(Vector2 local_point)

Parameters

local_point Vector2

to_local(Vector2)

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

Vector2 to_local(Vector2 global_point)

Parameters

global_point Vector2

translate(Vector2)

Translates the node by the given offset in local coordinates.

void translate(Vector2 offset)

Parameters

offset Vector2