Node2D¶
Inherits:CanvasItem<Node<Object
Inherited By:AnimatedSprite,AudioStreamPlayer2D,BackBufferCopy,Bone2D,CPUParticles2D,Camera2D,CanvasModulate,CollisionObject2D,CollisionPolygon2D,CollisionShape2D,Joint2D,Light2D,LightOccluder2D,Line2D,Listener2D,MeshInstance2D,MultiMeshInstance2D,Navigation2D,NavigationPolygonInstance,ParallaxLayer,Particles2D,Path2D,PathFollow2D,Polygon2D,Position2D,RayCast2D,RemoteTransform2D,Skeleton2D,Sprite,TileMap,TouchScreenButton,VisibilityNotifier2D,YSort
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 | |
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¶
Vector2global_position
Setter | set_global_position(value) |
Getter | get_global_position() |
Global position.
floatglobal_rotation
Setter | set_global_rotation(value) |
Getter | get_global_rotation() |
Global rotation in radians.
floatglobal_rotation_degrees
Setter | set_global_rotation_degrees(value) |
Getter | get_global_rotation_degrees() |
Global rotation in degrees.
Vector2global_scale
Setter | set_global_scale(value) |
Getter | get_global_scale() |
Global scale.
Transform2Dglobal_transform
Setter | set_global_transform(value) |
Getter | get_global_transform() |
GlobalTransform2D.
Vector2position
Default |
|
Setter | set_position(value) |
Getter | get_position() |
Position, relative to the node's parent.
floatrotation
Default |
|
Setter | set_rotation(value) |
Getter | get_rotation() |
Rotation in radians, relative to the node's parent.
floatrotation_degrees
Default |
|
Setter | set_rotation_degrees(value) |
Getter | get_rotation_degrees() |
Rotation in degrees, relative to the node's parent.
Vector2scale
Default |
|
Setter | set_scale(value) |
Getter | get_scale() |
The node's scale. Unscaled value:(1,1).
Transform2Dtransform
Setter | set_transform(value) |
Getter | get_transform() |
LocalTransform2D.
boolz_as_relative
Default |
|
Setter | set_z_as_relative(value) |
Getter | is_z_relative() |
Iftrue, 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.
intz_index
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 betweenVisualServer.CANVAS_ITEM_Z_MIN andVisualServer.CANVAS_ITEM_Z_MAX (inclusive).
Method Descriptions¶
voidapply_scale(Vector2 ratio)
Multiplies the current scale by theratio vector.
Returns the angle between the node and thepoint in radians.
Illustration of the returned angle.
Transform2Dget_relative_transform_to_parent(Node parent)const
Returns theTransform2D relative to this node's parent.
voidglobal_translate(Vector2 offset)
Adds theoffset vector to the node's global position.
voidlook_at(Vector2 point)
Rotates the node so it points towards thepoint, which is expected to use global coordinates.
Applies a local translation on the node's X axis based on theNode._process'sdelta. Ifscaled isfalse, normalizes the movement.
Applies a local translation on the node's Y axis based on theNode._process'sdelta. Ifscaled isfalse, normalizes the movement.
voidrotate(float radians)
Applies a rotation to the node, in radians, starting from its current rotation.
Transforms the provided local position into a position in global coordinate space. The input is expected to be local relative to theNode2D 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.
Transforms the provided global position into a position in local coordinate space. The output will be local relative to theNode2D 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.
voidtranslate(Vector2 offset)
Translates the node by the givenoffset in local coordinates.