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

  • Custom drawing in 2D
  • All 2D Demos

    Properties

    Methods

    Property Descriptions

  • Vector2 global_position Global position.

  • float global_rotation Global rotation in radians.

  • float global_rotation_degrees Global rotation in degrees.

  • Vector2 global_scale Global scale.

  • Transform2D global_transform Transform2D.

  • Vector2 position Position, relative to the node’s parent.

  • float rotation Rotation in radians, relative to the node’s parent.

  • float rotation_degrees Rotation in degrees, relative to the node’s parent.

  • Vector2 scale (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 Transform2D.

  • bool z_as_relative 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.

  • int z_index VisualServer.CANVAS_ITEM_Z_MIN and VisualServer.CANVAS_ITEM_Z_MAX (inclusive).

    Method Descriptions

  • apply_scale ( Vector2 ratio ) ratio vector.

  • float get_angle_to ( Vector2 point ) const point in radians. Illustration of the returned angle.

  • Transform2D get_relative_transform_to_parent ( Node parent ) const Transform2D relative to this node’s parent.

  • global_translate ( Vector2 offset ) offset vector to the node’s global position.

  • look_at ( Vector2 point ) point, which is expected to use global coordinates.

  • move_local_x ( float delta, bool scaled=false ) Node._process‘s delta. If scaled is false, normalizes the movement.

  • move_local_y ( float delta, bool scaled=false ) Node._process‘s delta. If scaled is false, normalizes the movement.

  • rotate ( float radians ) Applies a rotation to the node, in radians, starting from its current rotation.

  • Vector2 to_global ( Vector2 local_point ) const 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_local ( Vector2 global_point ) const 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.

  • translate ( Vector2 offset ) offset in local coordinates.