CollisionObject2D
Abstract base class for 2D physics objects.
CollisionObject2D.swift:23class CollisionObject2D
Abstract base class for 2D physics objects. CollisionObject2D
can hold any number of Shape2D
s for collision. Each shape must be assigned to a shape owner. Shape owners are not nodes and do not appear in the editor, but are accessible through code using the shape_owner_*
methods.
This object emits the following signals:
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
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.
Types
enum DisableMode
class Signal1
Signal support.
class Signal2
Signal support.
class Signal3
Signal support.
Type members
Instance members
var collisionLayer: UInt32
The physics layers this CollisionObject2D is in. Collision objects can exist in one or more of 32 different layers. See also
collisionMask
.var collisionMask: UInt32
The physics layers this CollisionObject2D scans. Collision objects can scan one or more of 32 different layers. See also
collisionLayer
.var collisionPriority: Double
The priority used to solve colliding when occurring penetration. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.
var disableMode: CollisionObject2D.DisableMode
Defines the behavior in physics when
processMode
is set todisabled
. SeeDisableMode
for more details about the different modes.var inputEvent: Signal1
Emitted when an input event occurs. Requires
inputPickable
to betrue
and at least onecollisionLayer
bit to be set. See_inputEvent(viewport:event:shapeIdx:)
for details.var inputPickable: Bool
If
true
, this object is pickable. A pickable object can detect the mouse pointer entering/leaving, and if the mouse is inside it, report input events. Requires at least onecollisionLayer
bit to be set.var mouseEntered: SimpleSignal
Emitted when the mouse pointer enters any of this object’s shapes. Requires
inputPickable
to betrue
and at least onecollisionLayer
bit to be set. Note that moving between different shapes within a singleCollisionObject2D
won’t cause this signal to be emitted.var mouseExited: SimpleSignal
Emitted when the mouse pointer exits all this object’s shapes. Requires
inputPickable
to betrue
and at least onecollisionLayer
bit to be set. Note that moving between different shapes within a singleCollisionObject2D
won’t cause this signal to be emitted.var mouseShapeEntered: Signal2
Emitted when the mouse pointer enters any of this object’s shapes or moves from one shape to another.
shapeIdx
is the child index of the newly enteredShape2D
. RequiresinputPickable
to betrue
and at least onecollisionLayer
bit to be set.var mouseShapeExited: Signal3
Emitted when the mouse pointer exits any of this object’s shapes.
shapeIdx
is the child index of the exitedShape2D
. RequiresinputPickable
to betrue
and at least onecollisionLayer
bit to be set.func createShapeOwner(Object?
) -> UInt32 Creates a new shape owner for the given object. Returns
owner_id
of the new owner for future reference.func getCollisionLayerValue(layerNumber: Int32
) -> Bool Returns whether or not the specified layer of the
collisionLayer
is enabled, given alayerNumber
between 1 and 32.func getCollisionMaskValue(layerNumber: Int32
) -> Bool Returns whether or not the specified layer of the
collisionMask
is enabled, given alayerNumber
between 1 and 32.func getRid(
) -> RID Returns the object’s
RID
.func getShapeOwnerOneWayCollisionMargin(ownerId: UInt32
) -> Double Returns the
one_way_collision_margin
of the shape owner identified by givenownerId
.func getShapeOwners(
) -> PackedInt32Array Returns an
GArray
ofowner_id
identifiers. You can use these ids in other methods that takeowner_id
as an argument.func isShapeOwnerDisabled(ownerId: UInt32
) -> Bool If
true
, the shape owner and its shapes are disabled.func isShapeOwnerOneWayCollisionEnabled(ownerId: UInt32
) -> Bool Returns
true
if collisions for the shape owner originating from thisCollisionObject2D
will not be reported to collided withCollisionObject2D
s.func removeShapeOwner(ownerId: UInt32
) Removes the given shape owner.
func setCollisionLayerValue(layerNumber: Int32, value: Bool
) Based on
value
, enables or disables the specified layer in thecollisionLayer
, given alayerNumber
between 1 and 32.func setCollisionMaskValue(layerNumber: Int32, value: Bool
) Based on
value
, enables or disables the specified layer in thecollisionMask
, given alayerNumber
between 1 and 32.func shapeFindOwner(shapeIndex: Int32
) -> UInt32 Returns the
owner_id
of the given shape.func shapeOwnerAddShape(ownerId: UInt32, shape: Shape2D?
) Adds a
Shape2D
to the shape owner.func shapeOwnerClearShapes(ownerId: UInt32
) Removes all shapes from the shape owner.
func shapeOwnerGetOwner(ownerId: UInt32
) -> Object? Returns the parent object of the given shape owner.
func shapeOwnerGetShape(ownerId: UInt32, shapeId: Int32
) -> Shape2D? Returns the
Shape2D
with the given ID from the given shape owner.func shapeOwnerGetShapeCount(ownerId: UInt32
) -> Int32 Returns the number of shapes the given shape owner contains.
func shapeOwnerGetShapeIndex(ownerId: UInt32, shapeId: Int32
) -> Int32 Returns the child index of the
Shape2D
with the given ID from the given shape owner.func shapeOwnerGetTransform(ownerId: UInt32
) -> Transform2D Returns the shape owner’s
Transform2D
.func shapeOwnerRemoveShape(ownerId: UInt32, shapeId: Int32
) Removes a shape from the given shape owner.
func shapeOwnerSetDisabled(ownerId: UInt32, disabled: Bool
) If
true
, disables the given shape owner.func shapeOwnerSetOneWayCollision(ownerId: UInt32, enable: Bool
) If
enable
istrue
, collisions for the shape owner originating from thisCollisionObject2D
will not be reported to collided withCollisionObject2D
s.func shapeOwnerSetOneWayCollisionMargin(ownerId: UInt32, margin: Double
) Sets the
one_way_collision_margin
of the shape owner identified by givenownerId
tomargin
pixels.func shapeOwnerSetTransform(ownerId: UInt32, transform: Transform2D
) Sets the
Transform2D
of the given shape owner.
Show implementation details (5)
Hide implementation details
func _inputEvent(viewport: Viewport?, event: InputEvent?, shapeIdx: Int32
) Accepts unhandled
InputEvent
s.shapeIdx
is the child index of the clickedShape2D
. Connect to [signal input_event] to easily pick up these events.func _mouseEnter(
) Called when the mouse pointer enters any of this object’s shapes. Requires
inputPickable
to betrue
and at least onecollisionLayer
bit to be set. Note that moving between different shapes within a singleCollisionObject2D
won’t cause this function to be called.func _mouseExit(
) Called when the mouse pointer exits all this object’s shapes. Requires
inputPickable
to betrue
and at least onecollisionLayer
bit to be set. Note that moving between different shapes within a singleCollisionObject2D
won’t cause this function to be called.func _mouseShapeEnter(shapeIdx: Int32
) Called when the mouse pointer enters any of this object’s shapes or moves from one shape to another.
shapeIdx
is the child index of the newly enteredShape2D
. RequiresinputPickable
to betrue
and at least onecollisionLayer
bit to be called.func _mouseShapeExit(shapeIdx: Int32
) Called when the mouse pointer exits any of this object’s shapes.
shapeIdx
is the child index of the exitedShape2D
. RequiresinputPickable
to betrue
and at least onecollisionLayer
bit to be called.
Subclasses
class Area2D
A region of 2D space that detects other
CollisionObject2D
s entering or exiting it.class PhysicsBody2D
Abstract base class for 2D game objects affected by physics.