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 ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) ApplyScale(ratio Vector2.XY)
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) GetAngleTo(point Vector2.XY) Angle.Radians
- func (self Instance) GetRelativeTransformToParent(parent Node.Instance) Transform2D.OriginXY
- func (self Instance) GlobalPosition() Vector2.XY
- func (self Instance) GlobalRotation() Angle.Radians
- func (self Instance) GlobalRotationDegrees() Angle.Degrees
- func (self Instance) GlobalScale() Vector2.XY
- func (self Instance) GlobalSkew() Float.X
- func (self Instance) GlobalTranslate(offset Vector2.XY)
- func (self Instance) ID() ID
- func (self Instance) LookAt(point Vector2.XY)
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) MoveLocalX(delta Float.X)
- func (self Instance) MoveLocalY(delta Float.X)
- func (self Instance) Position() Vector2.XY
- func (self Instance) Rotate(radians Angle.Radians)
- func (self Instance) Rotation() Angle.Radians
- func (self Instance) RotationDegrees() Angle.Degrees
- func (self Instance) Scale() Vector2.XY
- func (self Instance) SetGlobalPosition(value Vector2.XY)
- func (self Instance) SetGlobalRotation(value Angle.Radians)
- func (self Instance) SetGlobalRotationDegrees(value Angle.Degrees)
- func (self Instance) SetGlobalScale(value Vector2.XY)
- func (self Instance) SetGlobalSkew(value Float.X)
- func (self Instance) SetGlobalTransform(value Transform2D.OriginXY)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetPosition(value Vector2.XY)
- func (self Instance) SetRotation(value Angle.Radians)
- func (self Instance) SetRotationDegrees(value Angle.Degrees)
- func (self Instance) SetScale(value Vector2.XY)
- func (self Instance) SetSkew(value Float.X)
- func (self Instance) SetTransform(value Transform2D.OriginXY)
- func (self Instance) Skew() Float.X
- func (self Instance) ToGlobal(local_point Vector2.XY) Vector2.XY
- func (self Instance) ToLocal(global_point Vector2.XY) Vector2.XY
- func (self Instance) Translate(offset Vector2.XY)
- func (self Instance) Virtual(name string) reflect.Value
- type MoreArgs
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 Extension ¶
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
type 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.
type Instance ¶
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 (Instance) ApplyScale ¶
Multiplies the current scale by the 'ratio' vector.
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) GetAngleTo ¶
Returns the angle between the node and the 'point' in radians.
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 ¶
Global position. See also Position.
func (Instance) GlobalRotation ¶
Global rotation in radians. See also Rotation.
func (Instance) GlobalRotationDegrees ¶
Helper property to access GlobalRotation in degrees instead of radians. See also RotationDegrees.
func (Instance) GlobalScale ¶
Global scale. See also Scale.
func (Instance) GlobalSkew ¶
Global skew in radians. See also Skew.
func (Instance) GlobalTranslate ¶
Adds the 'offset' vector to the node's global position.
func (Instance) LookAt ¶
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 ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) MoveLocalX ¶
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 ¶
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 ¶
Position, relative to the node's parent. See also GlobalPosition.
func (Instance) Rotate ¶
Applies a rotation to the node, in radians, starting from its current rotation.
func (Instance) Rotation ¶
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 ¶
Helper property to access Rotation in degrees instead of radians. See also GlobalRotationDegrees.
func (Instance) Scale ¶
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 ¶
SetGlobalPosition sets the property returned by [GetGlobalPosition].
func (Instance) SetGlobalRotation ¶
SetGlobalRotation sets the property returned by [GetGlobalRotation].
func (Instance) SetGlobalRotationDegrees ¶
SetGlobalRotationDegrees sets the property returned by [GetGlobalRotationDegrees].
func (Instance) SetGlobalScale ¶
SetGlobalScale sets the property returned by [GetGlobalScale].
func (Instance) SetGlobalSkew ¶
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) SetPosition ¶
SetPosition sets the property returned by [GetPosition].
func (Instance) SetRotation ¶
SetRotation sets the property returned by [GetRotation].
func (Instance) SetRotationDegrees ¶
SetRotationDegrees sets the property returned by [GetRotationDegrees].
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 ¶
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 ¶
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 ¶
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.
type MoreArgs ¶
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) MoveLocalX ¶
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 ¶
Applies a local translation on the node's Y axis based on the Node.Process's 'delta'. If 'scaled' is false, normalizes the movement.