Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Node2D¶
Inherits: CanvasItem < Node < Object
Inherited By: AnimatedSprite2D, AudioListener2D, AudioStreamPlayer2D, BackBufferCopy, Bone2D, Camera2D, CanvasGroup, CanvasModulate, CollisionObject2D, CollisionPolygon2D, CollisionShape2D, CPUParticles2D, GPUParticles2D, Joint2D, Light2D, LightOccluder2D, Line2D, Marker2D, MeshInstance2D, MultiMeshInstance2D, NavigationLink2D, NavigationObstacle2D, NavigationRegion2D, ParallaxLayer, Path2D, PathFollow2D, Polygon2D, RayCast2D, RemoteTransform2D, ShapeCast2D, Skeleton2D, Sprite2D, TileMap, TouchScreenButton, VisibleOnScreenNotifier2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
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.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
Methods¶
void |
apply_scale ( Vector2 ratio ) |
get_angle_to ( Vector2 point ) const |
|
get_relative_transform_to_parent ( Node parent ) const |
|
void |
global_translate ( Vector2 offset ) |
void |
|
void |
move_local_x ( float delta, bool scaled=false ) |
void |
move_local_y ( float delta, bool scaled=false ) |
void |
|
void |
Property Descriptions¶
Vector2 global_position
Global position.
float global_rotation
Global rotation in radians.
float global_rotation_degrees
Helper property to access global_rotation in degrees instead of radians.
Vector2 global_scale
Global scale.
float global_skew
Global skew in radians.
Transform2D global_transform
void set_global_transform ( Transform2D value )
Transform2D get_global_transform ( )
Global Transform2D.
Vector2 position = Vector2(0, 0)
Position, relative to the node's parent.
float rotation = 0.0
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 rotation_degrees.
float rotation_degrees
Helper property to access rotation in degrees instead of radians.
Vector2 scale = Vector2(1, 1)
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.
float skew = 0.0
Slants the node.
Note: Skew is X axis only.
Transform2D transform
void set_transform ( Transform2D value )
Transform2D get_transform ( )
Local Transform2D.
Method Descriptions¶
void apply_scale ( Vector2 ratio )
Multiplies the current scale by the ratio
vector.
float get_angle_to ( Vector2 point ) const
Returns the angle between the node and the point
in radians.
Illustration of the returned angle.
Transform2D get_relative_transform_to_parent ( Node parent ) const
Returns the Transform2D relative to this node's parent.
void global_translate ( Vector2 offset )
Adds the offset
vector to the node's global position.
void look_at ( Vector2 point )
Rotates the node so it points