Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Node2D.swift:17class Node2D
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.
Superclasses
class CanvasItem
Abstract base class for everything in 2D space.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var globalPosition: Vector2
Global position.
var globalRotation: Double
Global rotation in radians.
var globalRotationDegrees: Double
Helper property to access
globalRotation
in degrees instead of radians.var globalScale: Vector2
Global scale.
var globalSkew: Double
Global skew in radians.
var globalTransform: Transform2D
Global
Transform2D
.var position: Vector2
Position, relative to the node’s parent.
var rotation: Double
Rotation in radians, relative to the node’s parent.
var rotationDegrees: Double
Helper property to access
rotation
in degrees instead of radians.var scale: Vector2
The node’s scale. Unscaled value:
(1, 1)
.var skew: Double
Slants the node.
var transform: Transform2D
Local
Transform2D
.func applyScale(ratio: Vector2
) Multiplies the current scale by the
ratio
vector.func getAngleTo(point: Vector2
) -> Double Returns the angle between the node and the
point
in radians.func getRelativeTransformToParent(Node?
) -> Transform2D Returns the
Transform2D
relative to this node’s parent.func globalTranslate(offset: Vector2
) Adds the
offset
vector to the node’s global position.func lookAt(point: Vector2
) Rotates the node so that its local +X axis points towards the
point
, which is expected to use global coordinates.func moveLocalX(delta: Double, scaled: Bool
) Applies a local translation on the node’s X axis based on the
_process(delta:)
’sdelta
. Ifscaled
isfalse
, normalizes the movement.func moveLocalY(delta: Double, scaled: Bool
) Applies a local translation on the node’s Y axis based on the
_process(delta:)
’sdelta
. Ifscaled
isfalse
, normalizes the movement.func rotate(radians: Double
) Applies a rotation to the node, in radians, starting from its current rotation.
func toGlobal(localPoint: Vector2
) -> Vector2 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 toLocal(globalPoint: Vector2
) -> Vector2 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 translate(offset: Vector2
) Translates the node by the given
offset
in local coordinates.
Subclasses
class AnimatedSprite2D
Sprite node that contains multiple textures as frames to play for animation.
class AudioListener2D
Overrides the location sounds are heard from.
class AudioStreamPlayer2D
Plays positional sound in 2D space.
class BackBufferCopy
A node that copies a region of the screen to a buffer for access in shader code.
class Bone2D
A joint used with
Skeleton2D
to control and animate other nodes.class CPUParticles2D
A CPU-based 2D particle emitter.
class Camera2D
Camera node for 2D scenes.
class CanvasGroup
Merges several 2D nodes into a single draw operation.
class CanvasModulate
A node that applies a color tint to a canvas.
class CollisionObject2D
Abstract base class for 2D physics objects.
class CollisionPolygon2D
A node that provides a polygon shape to a
CollisionObject2D
parent.class CollisionShape2D
A node that provides a
Shape2D
to aCollisionObject2D
parent.class GPUParticles2D
A 2D particle emitter.
class Joint2D
Abstract base class for all 2D physics joints.
class Light2D
Casts light in a 2D environment.
class LightOccluder2D
Occludes light cast by a Light2D, casting shadows.
class Line2D
A 2D polyline that can optionally be textured.
class Marker2D
Generic 2D position hint for editing.
class MeshInstance2D
Node used for displaying a
Mesh
in 2D.class MultiMeshInstance2D
Node that instances a
MultiMesh
in 2D.class Parallax2D
A node used to create a parallax scrolling background.
class ParallaxLayer
A parallax scrolling layer to be used with
ParallaxBackground
.class Path2D
Contains a
Curve2D
path forPathFollow2D
nodes to follow.class PathFollow2D
Point sampler for a
Path2D
.class Polygon2D
A 2D polygon.
class RayCast2D
A ray in 2D space, used to find the first
CollisionObject2D
it intersects.class RemoteTransform2D
RemoteTransform2D pushes its own
Transform2D
to anotherNode2D
derived node in the scene.class ShapeCast2D
A 2D shape that sweeps a region of space to detect
CollisionObject2D
s.class Skeleton2D
The parent of a hierarchy of
Bone2D
s, used to create a 2D skeletal animation.class Sprite2D
General-purpose sprite node.
class TileMap
Node for 2D tile-based maps.
class TileMapLayer
Node for 2D tile-based maps.
class TouchScreenButton
Button for touch screen devices for gameplay use.
class VisibleOnScreenNotifier2D
A rectangular region of 2D space that detects whether it is visible on screen.