Documentation
¶
Overview ¶
Abstract base class for 2D physics objects. graphics.gd/classdb/CollisionObject2D can hold any number of [graphics.gd/classdb/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.
Note: Only collisions between objects within the same canvas (graphics.gd/classdb/Viewport canvas or graphics.gd/classdb/CanvasLayer) are supported. The behavior of collisions between objects in different canvases is undefined.
Index ¶
- type Advanced
- type Any
- type DisableMode
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsCollisionObject2D() Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) CollisionLayer() int
- func (self Instance) CollisionMask() int
- func (self Instance) CollisionPriority() Float.X
- func (self Instance) CreateShapeOwner(owner Object.Instance) int
- func (self Instance) DisableMode() DisableMode
- func (self Instance) GetCollisionLayerValue(layer_number int) bool
- func (self Instance) GetCollisionMaskValue(layer_number int) bool
- func (self Instance) GetRid() RID.Body2D
- func (self Instance) GetShapeOwnerOneWayCollisionMargin(owner_id int) Float.X
- func (self Instance) GetShapeOwners() []int32
- func (self Instance) ID() ID
- func (self Instance) InputPickable() bool
- func (self Instance) IsShapeOwnerDisabled(owner_id int) bool
- func (self Instance) IsShapeOwnerOneWayCollisionEnabled(owner_id int) bool
- func (self Instance) OnInputEvent(cb func(viewport Node.Instance, event InputEvent.Instance, shape_idx int), ...)
- func (self Instance) OnMouseEntered(cb func(), flags ...Signal.Flags)
- func (self Instance) OnMouseExited(cb func(), flags ...Signal.Flags)
- func (self Instance) OnMouseShapeEntered(cb func(shape_idx int), flags ...Signal.Flags)
- func (self Instance) OnMouseShapeExited(cb func(shape_idx int), flags ...Signal.Flags)
- func (self Instance) RemoveShapeOwner(owner_id int)
- func (self Instance) SetCollisionLayer(value int)
- func (self Instance) SetCollisionLayerValue(layer_number int, value bool)
- func (self Instance) SetCollisionMask(value int)
- func (self Instance) SetCollisionMaskValue(layer_number int, value bool)
- func (self Instance) SetCollisionPriority(value Float.X)
- func (self Instance) SetDisableMode(value DisableMode)
- func (self Instance) SetInputPickable(value bool)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) ShapeFindOwner(shape_index int) int
- func (self Instance) ShapeOwnerAddShape(owner_id int, shape Shape2D.Instance)
- func (self Instance) ShapeOwnerClearShapes(owner_id int)
- func (self Instance) ShapeOwnerGetOwner(owner_id int) Object.Instance
- func (self Instance) ShapeOwnerGetShape(owner_id int, shape_id int) Shape2D.Instance
- func (self Instance) ShapeOwnerGetShapeCount(owner_id int) int
- func (self Instance) ShapeOwnerGetShapeIndex(owner_id int, shape_id int) int
- func (self Instance) ShapeOwnerGetTransform(owner_id int) Transform2D.OriginXY
- func (self Instance) ShapeOwnerRemoveShape(owner_id int, shape_id int)
- func (self Instance) ShapeOwnerSetDisabled(owner_id int, disabled bool)
- func (self Instance) ShapeOwnerSetOneWayCollision(owner_id int, enable bool)
- func (self Instance) ShapeOwnerSetOneWayCollisionMargin(owner_id int, margin Float.X)
- func (self Instance) ShapeOwnerSetTransform(owner_id int, transform Transform2D.OriginXY)
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
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 DisableMode ¶
type DisableMode int //gd:CollisionObject2D.DisableMode
const ( // When [graphics.gd/classdb/Node.Instance.ProcessMode] is set to [Node.ProcessModeDisabled], remove from the physics simulation to stop all physics interactions with this [graphics.gd/classdb/CollisionObject2D]. // // Automatically re-added to the physics simulation when the [graphics.gd/classdb/Node] is processed again. DisableModeRemove DisableMode = 0 // When [graphics.gd/classdb/Node.Instance.ProcessMode] is set to [Node.ProcessModeDisabled], make the body static. Doesn't affect [graphics.gd/classdb/Area2D]. [graphics.gd/classdb/PhysicsBody2D] can't be affected by forces or other bodies while static. // // Automatically set [graphics.gd/classdb/PhysicsBody2D] back to its original mode when the [graphics.gd/classdb/Node] is processed again. DisableModeMakeStatic DisableMode = 1 // When [graphics.gd/classdb/Node.Instance.ProcessMode] is set to [Node.ProcessModeDisabled], do not affect the physics simulation. DisableModeKeepActive DisableMode = 2 )
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]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
func (*Extension[T]) AsCollisionObject2D ¶
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 Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
type Instance [1]gdclass.CollisionObject2D
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) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) AsCollisionObject2D ¶
func (Instance) CollisionLayer ¶
func (Instance) CollisionMask ¶
func (Instance) CollisionPriority ¶
func (Instance) CreateShapeOwner ¶
Creates a new shape owner for the given object. Returns owner_id of the new owner for future reference.
func (Instance) DisableMode ¶
func (self Instance) DisableMode() DisableMode
func (Instance) GetCollisionLayerValue ¶
Returns whether or not the specified layer of the Instance.CollisionLayer is enabled, given a 'layer_number' between 1 and 32.
func (Instance) GetCollisionMaskValue ¶
Returns whether or not the specified layer of the Instance.CollisionMask is enabled, given a 'layer_number' between 1 and 32.
func (Instance) GetShapeOwnerOneWayCollisionMargin ¶
Returns the one_way_collision_margin of the shape owner identified by given 'owner_id'.
func (Instance) GetShapeOwners ¶
Returns an slice of owner_id identifiers. You can use these ids in other methods that take owner_id as an argument.
func (Instance) InputPickable ¶
func (Instance) IsShapeOwnerDisabled ¶
If true, the shape owner and its shapes are disabled.
func (Instance) IsShapeOwnerOneWayCollisionEnabled ¶
Returns true if collisions for the shape owner originating from this graphics.gd/classdb/CollisionObject2D will not be reported to collided with [graphics.gd/classdb/CollisionObject2D]s.
func (Instance) OnInputEvent ¶
func (Instance) OnMouseEntered ¶
func (Instance) OnMouseExited ¶
func (Instance) OnMouseShapeEntered ¶
func (Instance) OnMouseShapeExited ¶
func (Instance) RemoveShapeOwner ¶
Removes the given shape owner.
func (Instance) SetCollisionLayer ¶
func (Instance) SetCollisionLayerValue ¶
Based on 'value', enables or disables the specified layer in the Instance.CollisionLayer, given a 'layer_number' between 1 and 32.
func (Instance) SetCollisionMask ¶
func (Instance) SetCollisionMaskValue ¶
Based on 'value', enables or disables the specified layer in the Instance.CollisionMask, given a 'layer_number' between 1 and 32.
func (Instance) SetCollisionPriority ¶
func (Instance) SetDisableMode ¶
func (self Instance) SetDisableMode(value DisableMode)
func (Instance) SetInputPickable ¶
func (Instance) ShapeFindOwner ¶
Returns the owner_id of the given shape.
func (Instance) ShapeOwnerAddShape ¶
Adds a graphics.gd/classdb/Shape2D to the shape owner.
func (Instance) ShapeOwnerClearShapes ¶
Removes all shapes from the shape owner.
func (Instance) ShapeOwnerGetOwner ¶
Returns the parent object of the given shape owner.
func (Instance) ShapeOwnerGetShape ¶
Returns the graphics.gd/classdb/Shape2D with the given ID from the given shape owner.
func (Instance) ShapeOwnerGetShapeCount ¶
Returns the number of shapes the given shape owner contains.
func (Instance) ShapeOwnerGetShapeIndex ¶
Returns the child index of the graphics.gd/classdb/Shape2D with the given ID from the given shape owner.
func (Instance) ShapeOwnerGetTransform ¶
func (self Instance) ShapeOwnerGetTransform(owner_id int) Transform2D.OriginXY
Returns the shape owner's [Transform2D.OriginXY].
func (Instance) ShapeOwnerRemoveShape ¶
Removes a shape from the given shape owner.
func (Instance) ShapeOwnerSetDisabled ¶
If true, disables the given shape owner.
func (Instance) ShapeOwnerSetOneWayCollision ¶
If 'enable' is true, collisions for the shape owner originating from this graphics.gd/classdb/CollisionObject2D will not be reported to collided with [graphics.gd/classdb/CollisionObject2D]s.
func (Instance) ShapeOwnerSetOneWayCollisionMargin ¶
Sets the one_way_collision_margin of the shape owner identified by given 'owner_id' to 'margin' pixels.
func (Instance) ShapeOwnerSetTransform ¶
func (self Instance) ShapeOwnerSetTransform(owner_id int, transform Transform2D.OriginXY)
Sets the [Transform2D.OriginXY] of the given shape owner.
type Interface ¶
type Interface interface { // Accepts unhandled [graphics.gd/classdb/InputEvent]s. 'shape_idx' is the child index of the clicked [graphics.gd/classdb/Shape2D]. Connect to [Instance.OnInputEvent] to easily pick up these events. // // Note: [Interface.InputEvent] requires [Instance.InputPickable] to be true and at least one [Instance.CollisionLayer] bit to be set. InputEvent(viewport Viewport.Instance, event InputEvent.Instance, shape_idx int) // Called when the mouse pointer enters any of this object's shapes. Requires [Instance.InputPickable] to be true and at least one [Instance.CollisionLayer] bit to be set. Note that moving between different shapes within a single [graphics.gd/classdb/CollisionObject2D] won't cause this function to be called. MouseEnter() // Called when the mouse pointer exits all this object's shapes. Requires [Instance.InputPickable] to be true and at least one [Instance.CollisionLayer] bit to be set. Note that moving between different shapes within a single [graphics.gd/classdb/CollisionObject2D] won't cause this function to be called. MouseExit() // Called when the mouse pointer enters any of this object's shapes or moves from one shape to another. 'shape_idx' is the child index of the newly entered [graphics.gd/classdb/Shape2D]. Requires [Instance.InputPickable] to be true and at least one [Instance.CollisionLayer] bit to be called. MouseShapeEnter(shape_idx int) // Called when the mouse pointer exits any of this object's shapes. 'shape_idx' is the child index of the exited [graphics.gd/classdb/Shape2D]. Requires [Instance.InputPickable] to be true and at least one [Instance.CollisionLayer] bit to be called. MouseShapeExit(shape_idx int) }