Node2D
Inherited By: AnimatedSprite, , BackBufferCopy, , CPUParticles2D, , CanvasModulate, , CollisionPolygon2D, , Joint2D, , LightOccluder2D, , Listener2D, , MultiMeshInstance2D, , NavigationPolygonInstance, , Particles2D, , PathFollow2D, , Position2D, , RemoteTransform2D, , Sprite, , TouchScreenButton, , YSort
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
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
Methods
void | ( Vector2 ratio ) |
get_angle_to ( point ) const | |
( Node parent ) const | |
void | ( Vector2 offset ) |
void | ( Vector2 point ) |
void | |
void | ( float delta, scaled=false ) |
void | rotate ( radians ) |
( Vector2 local_point ) const | |
to_local ( global_point ) const | |
void | translate ( offset ) |
- global_position
Setter | set_global_position(value) |
Getter | get_global_position() |
Global position.
Setter | set_global_rotation(value) |
Getter | get_global_rotation() |
Global rotation in radians.
- float global_rotation_degrees
Global rotation in degrees.
- global_scale
Setter | set_global_scale(value) |
Getter | get_global_scale() |
Global scale.
- Transform2D global_transform
Setter | set_global_transform(value) |
Getter | get_global_transform() |
Global .
- Vector2 position
Default |
|
Setter | set_position(value) |
Getter | get_position() |
Position, relative to the node’s parent.
- rotation
Rotation in radians, relative to the node’s parent.
- float rotation_degrees
Default |
|
Setter | set_rotation_degrees(value) |
Getter | get_rotation_degrees() |
Rotation in degrees, relative to the node’s parent.
- scale
Default | |
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.
- Transform2D transform
Setter | set_transform(value) |
Getter | get_transform() |
Local .
- bool z_as_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.
Default |
|
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 and VisualServer.CANVAS_ITEM_Z_MAX (inclusive).
Method Descriptions
- void apply_scale ( Vector2 ratio )
Multiplies the current scale by the ratio
vector.
- get_angle_to ( Vector2 point ) const
Returns the angle between the node and the point
in radians.
- Transform2D get_relative_transform_to_parent ( parent ) const
Returns the Transform2D relative to this node’s parent.
- void global_translate ( offset )
Adds the offset
vector to the node’s global position.
- void look_at ( Vector2 point )
Rotates the node so it points towards the point
, which is expected to use global coordinates.
- void move_local_x ( delta, bool scaled=false )
Applies a local translation on the node’s X axis based on the ‘s . If scaled
is false
, normalizes the movement.
- void move_local_y ( float delta, scaled=false )
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 rotate ( radians )
Applies a rotation to the node, in radians, starting from its current rotation.
- Vector2 to_global ( 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.
- void translate ( Vector2 offset )
Translates the node by the given offset
in local coordinates.