Skip to main content

Body Event

Description:

  This is just a demonstration record showing some signal slot events that are used when the receivingContact property of a Body is set to true. And they are meant to be used for collision detection between Body objects.

Usage:

-- you can register for these events using codes
body.receivingContact = true
body:slot("ContactStart", function(other: Body, point: Vec2, normal: Vec2, enabled: boolean)
print("A body has contacted", other, point, normal, enabled)
end)

BodyEnter

Type: Node Event.

Description:

  Triggers when a Body object collides with a sensor object. This event triggers only when the Body attached with any fixture as sensor.

Signature:

["BodyEnter"]: function(other: Body, sensorTag: integer)

Parameters:

ParameterTypeDescription
otherBodyThe other Body object that the current Body is colliding with.
sensorTagintegerThe tag of the sensor that triggered this collision.

BodyLeave

Type: Node Event.

Description:

  Triggers when a Body object is no longer colliding with a sensor object. This event triggers only when the Body attached with any fixture as sensor.

Signature:

["BodyLeave"]: function(other: Body, sensorTag: integer)

Parameters:

ParameterTypeDescription
otherBodyThe other Body object that the current Body is no longer colliding with.
sensorTagintegerThe tag of the sensor that triggered this collision.

ContactStart

Type: Node Event.

Description:

  Triggers when a Body object starts to collide with another object. This event triggers only when the receivingContact property of the Body is set to true.

Signature:

["ContactStart"]: function(other: Body, point: Vec2, normal: Vec2, enabled: boolean)

Parameters:

ParameterTypeDescription
otherBodyThe other Body object that the current Body is colliding with.
pointVec2The point of collision in world coordinates.
normalVec2The normal vector of the contact surface in world coordinates.
enabledbooleanWhether the contact is enabled or not. Collisions that are filtered out will still trigger this event, but the enabled state will be false.

ContactEnd

Type: Node Event.

Description:

  Triggers when a Body object stops colliding with another object. This event triggers only when the receivingContact property of the Body is set to true.

Signature:

["ContactEnd"]: function(other: Body, point: Vec2, normal: Vec2)

Parameters:

ParameterTypeDescription
otherBodyThe other Body object that the current Body is no longer colliding with.
pointVec2The point of collision in world coordinates.
normalVec2The normal vector of the contact surface in world coordinates.