Node2D

Inherits: CanvasItem < Node < Object

Inherited By: RemoteTransform2D, Joint2D, VisibilityNotifier2D, Navigation2D, CollisionPolygon2D, TouchScreenButton, Particles2D, AnimatedSprite, RayCast2D, Light2D, Path2D, Line2D, AudioStreamPlayer2D, CanvasModulate, Sprite, CollisionShape2D, NavigationPolygonInstance, PathFollow2D, ParallaxLayer, Polygon2D, Position2D, LightOccluder2D, CollisionObject2D, BackBufferCopy, YSort, TileMap, Camera2D

Category: Core

Brief Description

A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.

Member Functions

void apply_scale ( Vector2 ratio )
float get_angle_to ( Vector2 point ) const
Transform2D get_relative_transform_to_parent ( Node parent ) const
float get_rotation ( ) const
void global_translate ( Vector2 offset )
void look_at ( Vector2 point )
void move_local_x ( float delta, bool scaled=false )
void move_local_y ( float delta, bool scaled=false )
void rotate ( float radians )
void set_rotation ( float radians )
Vector2 to_global ( Vector2 local_point ) const
Vector2 to_local ( Vector2 global_point ) const
void translate ( Vector2 offset )

Member Variables

  • 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 - Global Transform2D.
  • Vector2 position - Position, relative to the node’s parent.
  • float rotation_degrees - Rotation in degrees, relative to the node’s parent.
  • Vector2 scale - The node’s scale. Unscaled value: (1, 1)
  • Transform2D transform - Local Transform2D.
  • int z - Z-index. Controls the order in which the nodes render. A node with a higher Z-index will display in front of others.
  • 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.

Description

A 2D game object, with a position, rotation and scale. All 2D physics nodes and sprites inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control on the node’s render order.

Member Function Description

  • void apply_scale ( Vector2 ratio )

Multiplies the current scale by the ‘ratio’ vector.

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

Returns the Transform2D relative to this node’s parent.

  • float get_rotation ( ) const
  • void global_translate ( Vector2 offset )

Adds the ‘offset’ vector to the node’s global position.

Rotates the node so it points towards the ‘point’.

  • void move_local_x ( float delta, bool scaled=false )

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_y ( float delta, bool 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 ( float radians )

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

  • void set_rotation ( float radians )

Converts a local point’s coordinates to global coordinates.

Converts a global point’s coordinates to local coordinates.

  • void translate ( Vector2 offset )

Translates the node by the given offset in local coordinates.