Node2D

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

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.

Note: Since both Node2D and Control inherit from CanvasItem, they share several concepts from the class such as the CanvasItem.ZIndex and CanvasItem.Visible properties.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsNode2D() Instance
}

type Expanded

type Expanded = MoreArgs

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsCanvasItem

func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance

func (*Extension[T]) AsNode

func (self *Extension[T]) AsNode() Node.Instance

func (*Extension[T]) AsNode2D

func (self *Extension[T]) AsNode2D() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Node2D

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) ApplyScale

func (self Instance) ApplyScale(ratio Vector2.XY)

Multiplies the current scale by the 'ratio' vector.

func (Instance) AsCanvasItem

func (self Instance) AsCanvasItem() CanvasItem.Instance

func (Instance) AsNode

func (self Instance) AsNode() Node.Instance

func (Instance) AsNode2D

func (self Instance) AsNode2D() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) GetAngleTo

func (self Instance) GetAngleTo(point Vector2.XY) Angle.Radians

Returns the angle between the node and the 'point' in radians.

Illustration of the returned angle.

func (Instance) GetRelativeTransformToParent

func (self Instance) GetRelativeTransformToParent(parent Node.Instance) Transform2D.OriginXY

Returns the Transform2D.OriginXY relative to this node's parent.

func (Instance) GlobalPosition

func (self Instance) GlobalPosition() Vector2.XY

Global position. See also Position.

func (Instance) GlobalRotation

func (self Instance) GlobalRotation() Angle.Radians

Global rotation in radians. See also Rotation.

func (Instance) GlobalRotationDegrees

func (self Instance) GlobalRotationDegrees() Angle.Degrees

Helper property to access GlobalRotation in degrees instead of radians. See also RotationDegrees.

func (Instance) GlobalScale

func (self Instance) GlobalScale() Vector2.XY

Global scale. See also Scale.

func (Instance) GlobalSkew

func (self Instance) GlobalSkew() Float.X

Global skew in radians. See also Skew.

func (Instance) GlobalTranslate

func (self Instance) GlobalTranslate(offset Vector2.XY)

Adds the 'offset' vector to the node's global position.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) LookAt

func (self Instance) LookAt(point Vector2.XY)

Rotates the node so that its local +X axis points towards the 'point', which is expected to use global coordinates.

'point' should not be the same as the node's position, otherwise the node always looks to the right.

func (Instance) MoreArgs

func (self Instance) MoreArgs() MoreArgs

MoreArgs enables certain functions to be called with additional 'optional' arguments.

func (Instance) MoveLocalX

func (self Instance) MoveLocalX(delta Float.X)

Applies a local translation on the node's X axis based on the Node.Process's 'delta'. If 'scaled' is false, normalizes the movement.

func (Instance) MoveLocalY

func (self Instance) MoveLocalY(delta Float.X)

Applies a local translation on the node's Y axis based on the Node.Process's 'delta'. If 'scaled' is false, normalizes the movement.

func (Instance) Position

func (self Instance) Position() Vector2.XY

Position, relative to the node's parent. See also GlobalPosition.

func (Instance) Rotate

func (self Instance) Rotate(radians Angle.Radians)

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

func (Instance) Rotation

func (self Instance) Rotation() Angle.Radians

Rotation in radians, relative to the node's parent. See also GlobalRotation.

Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use RotationDegrees.

func (Instance) RotationDegrees

func (self Instance) RotationDegrees() Angle.Degrees

Helper property to access Rotation in degrees instead of radians. See also GlobalRotationDegrees.

func (Instance) Scale

func (self Instance) Scale() Vector2.XY

The node's scale, relative to the node's parent. Unscaled value: (1, 1). See also GlobalScale.

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.

func (Instance) SetGlobalPosition

func (self Instance) SetGlobalPosition(value Vector2.XY)

SetGlobalPosition sets the property returned by [GetGlobalPosition].

func (Instance) SetGlobalRotation

func (self Instance) SetGlobalRotation(value Angle.Radians)

SetGlobalRotation sets the property returned by [GetGlobalRotation].

func (Instance) SetGlobalRotationDegrees

func (self Instance) SetGlobalRotationDegrees(value Angle.Degrees)

SetGlobalRotationDegrees sets the property returned by [GetGlobalRotationDegrees].

func (Instance) SetGlobalScale

func (self Instance) SetGlobalScale(value Vector2.XY)

SetGlobalScale sets the property returned by [GetGlobalScale].

func (Instance) SetGlobalSkew

func (self Instance) SetGlobalSkew(value Float.X)

SetGlobalSkew sets the property returned by [GetGlobalSkew].

func (Instance) SetGlobalTransform

func (self Instance) SetGlobalTransform(value Transform2D.OriginXY)

Global Transform2D.OriginXY. See also Transform.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetPosition

func (self Instance) SetPosition(value Vector2.XY)

SetPosition sets the property returned by [GetPosition].

func (Instance) SetRotation

func (self Instance) SetRotation(value Angle.Radians)

SetRotation sets the property returned by [GetRotation].

func (Instance) SetRotationDegrees

func (self Instance) SetRotationDegrees(value Angle.Degrees)

SetRotationDegrees sets the property returned by [GetRotationDegrees].

func (Instance) SetScale

func (self Instance) SetScale(value Vector2.XY)

SetScale sets the property returned by [GetScale].

func (Instance) SetSkew

func (self Instance) SetSkew(value Float.X)

SetSkew sets the property returned by [GetSkew].

func (Instance) SetTransform

func (self Instance) SetTransform(value Transform2D.OriginXY)

The node's Transform2D.OriginXY, relative to the node's parent. See also GlobalTransform.

func (Instance) Skew

func (self Instance) Skew() Float.X

If set to a non-zero value, slants the node in one direction or another. This can be used for pseudo-3D effects. See also GlobalSkew.

Note: Skew is performed on the X axis only, and between rotation and scaling.

Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use skew = deg_to_rad(value_in_degrees).

func (Instance) ToGlobal

func (self Instance) ToGlobal(local_point Vector2.XY) Vector2.XY

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.

func (Instance) ToLocal

func (self Instance) ToLocal(global_point Vector2.XY) Vector2.XY

Transforms the provided global position into a position in local coordinate space. The output will be local relative to the 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.

func (Instance) Translate

func (self Instance) Translate(offset Vector2.XY)

Translates the node by the given 'offset' in local coordinates.

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type MoreArgs

type MoreArgs [1]gdclass.Node2D

MoreArgs is a container for Instance functions with additional 'optional' arguments.

func (MoreArgs) MoveLocalX

func (self MoreArgs) MoveLocalX(delta Float.X, scaled bool)

Applies a local translation on the node's X axis based on the Node.Process's 'delta'. If 'scaled' is false, normalizes the movement.

func (MoreArgs) MoveLocalY

func (self MoreArgs) MoveLocalY(delta Float.X, scaled bool)

Applies a local translation on the node's Y axis based on the Node.Process's 'delta'. If 'scaled' is false, normalizes the movement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL