CollisionObject2D
A base 2D physics collision object.
Bodies and areas inherit CollisionObject2D. Child CollisionShapes and Shape resources define geometry; visible sprites/meshes do not create it automatically. Layer defines membership; Mask filters detection/interaction.
Layer number 3 corresponds to bit value 4. SetCollisionLayerValue/SetCollisionMaskValue accept a number from 1–32, not a bitmask. Use GetRid for ray exclusion, not GetInstanceId. A query shape index refers to physics shapes, not an arbitrary hierarchy child index.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties5
CollisionLayerProperty
public uint CollisionLayer { get; set; }Bitmask of object membership in 2D physics layers. Layer 3 has value 4; mask 3 includes layers 1 and 2. Distinct from the CollisionMask filter.
CollisionMaskProperty
public uint CollisionMask { get; set; }Bitmask filtering interaction or detection. For Area2D it selects detected-body layers; body contact does not require identical reciprocal masks. Rays and navigation have separate filters.
CollisionPriorityProperty
public float CollisionPriority { get; set; }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.
DisableModeProperty
public CollisionObject2D.DisableModeEnum DisableMode { get; set; }Defines the behavior in physics when Entity.ProcessMode is set to Entity.ProcessModeEnum.Disabled.
InputPickableProperty
public bool InputPickable { get; set; }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 one CollisionObject2D.CollisionLayer bit to be set.
Methods41
CreateShapeOwneruint
public uint CreateShapeOwner(ReckfellObject owner);Creates a new shape owner for the given object. Returns owner_id of the new owner for future reference.
| Name | Type | Default |
|---|---|---|
owner | ReckfellObject | — |
uintGetCollisionLayeruint
public uint GetCollisionLayer();uintGetCollisionLayerValuebool
public bool GetCollisionLayerValue(int layerNumber);Tests one membership bit by layer number 1–32, not an assembled bitmask.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
layerNumberLayer number from 1 through 32. Number 3 selects the bit with value 4.
booltrue if the selected bit is set; false if cleared. An invalid number reports an error and returns false.
GetCollisionMaskuint
public uint GetCollisionMask();uintGetCollisionMaskValuebool
public bool GetCollisionMaskValue(int layerNumber);Tests one filter bit by layer number 1–32, not an assembled bitmask.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
layerNumberLayer number from 1 through 32. Number 3 selects the bit with value 4.
booltrue if the selected bit is set; false if cleared. An invalid number reports an error and returns false.
GetCollisionPriorityfloat
public float GetCollisionPriority();floatGetDisableModeCollisionObject2D.DisableModeEnum
public CollisionObject2D.DisableModeEnum GetDisableMode();CollisionObject2D.DisableModeEnumGetShapeOwnerOneWayCollisionDirectionVector2
public Vector2 GetShapeOwnerOneWayCollisionDirection(uint ownerId);Returns the one_way_collision_direction of the shape owner identified by the given owner_id.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
Vector2GetShapeOwnerOneWayCollisionMarginfloat
public float GetShapeOwnerOneWayCollisionMargin(uint ownerId);Returns the one_way_collision_margin of the shape owner identified by given owner_id.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
floatGetShapeOwnersint[]
public int[] GetShapeOwners();Returns an Reckfell.Collections.Array of owner_id identifiers. You can use these ids in other methods that take owner_id as an argument.
int[]IsPickablebool
public bool IsPickable();boolIsShapeOwnerDisabledbool
public bool IsShapeOwnerDisabled(uint ownerId);If true, the shape owner and its shapes are disabled.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
boolIsShapeOwnerOneWayCollisionEnabledbool
public bool IsShapeOwnerOneWayCollisionEnabled(uint ownerId);Returns true if collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
boolRemoveShapeOwnervoid
public void RemoveShapeOwner(uint ownerId);Removes the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
SetCollisionLayervoid
public void SetCollisionLayer(uint layer);| Name | Type | Default |
|---|---|---|
layer | uint | — |
SetCollisionLayerValuevoid
public void SetCollisionLayerValue(int layerNumber, bool value);Changes one membership bit while preserving the others. Assign the CollisionLayer property to replace the entire mask.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
layerNumberLayer number 1–32, not a mask value. Out-of-range changes are rejected with an error message.
valuetrue sets the selected bit; false clears it.
SetCollisionMaskvoid
public void SetCollisionMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetCollisionMaskValuevoid
public void SetCollisionMaskValue(int layerNumber, bool value);Changes one filter bit while preserving the others. Assign the CollisionMask property to replace the entire mask.
| Name | Type | Default |
|---|---|---|
layerNumber | int | — |
value | bool | — |
layerNumberLayer number 1–32, not a mask value. Out-of-range changes are rejected with an error message.
valuetrue sets the selected bit; false clears it.
SetCollisionPriorityvoid
public void SetCollisionPriority(float priority);| Name | Type | Default |
|---|---|---|
priority | float | — |
SetDisableModevoid
public void SetDisableMode(CollisionObject2D.DisableModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | CollisionObject2D.DisableModeEnum | — |
SetPickablevoid
public void SetPickable(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
ShapeFindOwneruint
public uint ShapeFindOwner(int shapeIndex);Returns the owner_id of the given shape.
| Name | Type | Default |
|---|---|---|
shapeIndex | int | — |
uintShapeOwnerAddShapevoid
public void ShapeOwnerAddShape(uint ownerId, Shape2D shape);Adds a Shape2D to the shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
shape | Shape2D | — |
ShapeOwnerClearShapesvoid
public void ShapeOwnerClearShapes(uint ownerId);Removes all shapes from the shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
ShapeOwnerGetOwnerReckfellObject
public ReckfellObject ShapeOwnerGetOwner(uint ownerId);Returns the parent object of the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
ReckfellObjectShapeOwnerGetShapeShape2D
public Shape2D ShapeOwnerGetShape(uint ownerId, int shapeId);Returns the Shape2D with the given ID from the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
shapeId | int | — |
Shape2DShapeOwnerGetShapeCountint
public int ShapeOwnerGetShapeCount(uint ownerId);Returns the number of shapes the given shape owner contains.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
intShapeOwnerGetShapeIndexint
public int ShapeOwnerGetShapeIndex(uint ownerId, int shapeId);Returns the child index of the Shape2D with the given ID from the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
shapeId | int | — |
intShapeOwnerGetTransformTransform2D
public Transform2D ShapeOwnerGetTransform(uint ownerId);Returns the shape owner's Transform2D.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
Transform2DShapeOwnerRemoveShapevoid
public void ShapeOwnerRemoveShape(uint ownerId, int shapeId);Removes a shape from the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
shapeId | int | — |
ShapeOwnerSetDisabledvoid
public void ShapeOwnerSetDisabled(uint ownerId, bool disabled);If true, disables the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
disabled | bool | — |
ShapeOwnerSetOneWayCollisionvoid
public void ShapeOwnerSetOneWayCollision(uint ownerId, bool enable);If enable is true, collisions for the shape owner originating from this CollisionObject2D will not be reported to collided with CollisionObject2Ds.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
enable | bool | — |
ShapeOwnerSetOneWayCollisionDirectionvoid
public void ShapeOwnerSetOneWayCollisionDirection(uint ownerId, Vector2 direction);Sets the one_way_collision_direction of the shape owner identified by the given owner_id to direction.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
direction | Vector2 | — |
ShapeOwnerSetOneWayCollisionMarginvoid
public void ShapeOwnerSetOneWayCollisionMargin(uint ownerId, float margin);Sets the one_way_collision_margin of the shape owner identified by given owner_id to margin pixels.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
margin | float | — |
ShapeOwnerSetTransformvoid
public void ShapeOwnerSetTransform(uint ownerId, Transform2D transform);Sets the Transform2D of the given shape owner.
| Name | Type | Default |
|---|---|---|
ownerId | uint | — |
transform | Transform2D | — |
_InputEventvoid
public virtual void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx);Detects unhandled mouse and touch InputEvents through event when they happen while hovering over the object. Gesture events are not detected. viewport is the Viewport that the event originated in (for viewports other than the main one to be detected, Viewport.PhysicsObjectPicking needs to be set to true). shape_idx is the index of the detected shape from PhysicsServer2D.
See also Entity._UnhandledInput, CollisionObject2D.ShapeFindOwner, and CollisionObject2D.ShapeOwnerGetOwner.
Note: InputEventScreenDrag events are triggered if the drag events started while hovering the object, or when the object is in the path of the drag event.
Note: CollisionObject2D.InputEvent requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set.
| Name | Type | Default |
|---|---|---|
viewport | Viewport | — |
event | InputEvent | — |
shapeIdx | int | — |
_MouseEntervoid
public virtual void _MouseEnter();Called when the mouse pointer enters any of this object's shapes. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
_MouseExitvoid
public virtual void _MouseExit();Called when the mouse pointer exits all this object's shapes. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this function to be called.
_MouseShapeEntervoid
public virtual void _MouseShapeEnter(int shapeIdx);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 Shape2D. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be called.
| Name | Type | Default |
|---|---|---|
shapeIdx | int | — |
_MouseShapeExitvoid
public virtual void _MouseShapeExit(int shapeIdx);Called when the mouse pointer exits any of this object's shapes. shape_idx is the child index of the exited Shape2D. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be called.
| Name | Type | Default |
|---|---|---|
shapeIdx | int | — |
Signals and events5
InputEventEvent
public event CollisionObject2D.InputEventEventHandler InputEvent;Detects unhandled mouse and touch InputEvents through event when they happen while hovering over the object. Gesture events are not detected. viewport is the Viewport that the event originated in (for viewports other than the main one to be detected, Viewport.PhysicsObjectPicking needs to be set to true). shape_idx is the index of the detected shape from PhysicsServer2D.
See also Entity._UnhandledInput, CollisionObject2D.ShapeFindOwner, and CollisionObject2D.ShapeOwnerGetOwner.
Note: InputEventScreenDrag events are triggered if the drag events started while hovering the object, or when the object is in the path of the drag event.
Note: CollisionObject2D.InputEvent requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set.
| Name | Type | Default |
|---|---|---|
viewport | Entity | — |
event | InputEvent | — |
shapeIdx | long | — |
MouseEnteredEvent
public event Action MouseEntered;Emitted when the mouse pointer enters any of this object's shapes. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
MouseExitedEvent
public event Action MouseExited;Emitted when the mouse pointer exits all this object's shapes. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set. Note that moving between different shapes within a single CollisionObject2D won't cause this signal to be emitted.
Note: Due to the lack of continuous collision detection, this signal may not be emitted in the expected order if the mouse moves fast enough and the CollisionObject2D's area is small. This signal may also not be emitted if another CollisionObject2D is overlapping the CollisionObject2D in question.
MouseShapeEnteredEvent
public event CollisionObject2D.MouseShapeEnteredEventHandler MouseShapeEntered;Emitted 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 Shape2D. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set.
| Name | Type | Default |
|---|---|---|
shapeIdx | long | — |
MouseShapeExitedEvent
public event CollisionObject2D.MouseShapeExitedEventHandler MouseShapeExited;Emitted when the mouse pointer exits any of this object's shapes. shape_idx is the child index of the exited Shape2D. Requires CollisionObject2D.InputPickable to be true and at least one CollisionObject2D.CollisionLayer bit to be set.
| Name | Type | Default |
|---|---|---|
shapeIdx | long | — |
CollisionObject2D.DisableModeEnum
| Value | Description |
|---|---|
KeepActive = 2 | When |
MakeStatic = 1 | When |
Remove = 0 | When |