Skip to main content

Body

Description:

  A class represents a physics body in the world.

Class Object: Body Class.

Inherits from: Node.

world

Type: Readonly Field.

Description:

  The physics world that the body belongs to.

Signature:

const world: PhysicsWorld

bodyDef

Type: Readonly Field.

Description:

  The definition of the body.

Signature:

const bodyDef: BodyDef

mass

Type: Readonly Field.

Description:

  The mass of the body.

Signature:

const mass: number

sensor

Type: Readonly Field.

Description:

  Whether the body is used as a sensor or not.

Signature:

const sensor: boolean

velocityX

Type: Field.

Description:

  The x-axis velocity of the body.

Signature:

velocityX: number

velocityY

Type: Field.

Description:

  The y-axis velocity of the body.

Signature:

velocityY: number

velocity

Type: Field.

Description:

  The velocity of the body as a Vec2.

Signature:

velocity: Vec2

angularRate

Type: Field.

Description:

  The angular rate of the body.

Signature:

angularRate: number

group

Type: Field.

Description:

  The collision group that the body belongs to.

Signature:

group: integer

linearDamping

Type: Field.

Description:

  The linear damping of the body.

Signature:

linearDamping: number

angularDamping

Type: Field.

Description:

  The angular damping of the body.

Signature:

angularDamping: number

owner

Type: Field.

Description:

  The reference for an owner of the body.

Signature:

owner: Object

receivingContact

Type: Field.

Description:

  Whether the body is currently receiving contact events or not.

Signature:

receivingContact: boolean

applyLinearImpulse

Type: Function.

Description:

  Applies a linear impulse to the body at a specified position.

Signature:

applyLinearImpulse: function(self: Body, impulse: Vec2, pos: Vec2)

Parameters:

ParameterTypeDescription
impulseVec2The linear impulse to apply.
posVec2The position at which to apply the impulse.

applyAngularImpulse

Type: Function.

Description:

  Applies an angular impulse to the body.

Signature:

applyAngularImpulse: function(self: Body, impulse: number)

Parameters:

ParameterTypeDescription
impulsenumberThe angular impulse to apply.

removeSensorByTag

Type: Function.

Description:

  Removes the sensor with the specified tag from the body.

Signature:

removeSensorByTag: function(self: Body, tag: integer): boolean

Parameters:

ParameterTypeDescription
tagintegerThe tag of the sensor to remove.

Returns:

Return TypeDescription
booleanWhether a sensor with the specified tag was found and removed.

attach

Type: Function.

Description:

  Attaches a fixture to the body.

Signature:

attach: function(self: Body, fixtureDef: FixtureDef)

Parameters:

ParameterTypeDescription
fixtureDefFixtureDefThe fixture definition for the fixture to attach.

getSensorByTag

Type: Function.

Description:

  Returns the sensor with the given tag.

Signature:

getSensorByTag: function(self: Body, tag: integer): Sensor

Parameters:

ParameterTypeDescription
tagintegerthe tag of the sensor to get.

Returns:

Return TypeDescription
Sensorthe sensor with the given tag.

removeSensor

Type: Function.

Description:

  Removes the given sensor from the body's sensor list.

Signature:

removeSensor: function(self: Body, sensor: Sensor): boolean

Parameters:

ParameterTypeDescription
sensorSensorthe sensor to remove.

Returns:

Return TypeDescription
booleantrue if the sensor was successfully removed, false otherwise.

attachSensor

Type: Function.

Description:

  Attaches a new sensor with the given tag and fixture definition to the body.

Signature:

attachSensor: function(self: Body, tag: integer, fixtureDef: FixtureDef): Sensor

Parameters:

ParameterTypeDescription
tagintegerthe tag of the sensor to attach.
fixtureDefFixtureDefthe fixture definition of the sensor.

Returns:

Return TypeDescription
Sensorthe newly attached sensor.

onContactFilter

Type: Function.

Description:

  Register a function to be called when the body begins to receive contact events. Return false from this function to prevent colliding.

Signature:

onContactFilter: function(self: Body, filter: function(other: Body): boolean)

Parameters:

ParameterTypeDescription
filterfunctionThe filter function to set.

onBodyEnter

Type: Function.

Description:

  Registers a callback function for when the body enters a sensor.

Signature:

onBodyEnter: function(self: Body, callback: function(other: Body, sensorTag: integer))

Parameters:

ParameterTypeDescription
callbackfunctionThe callback function for when the body enters a sensor.

onBodyLeave

Type: Function.

Description:

  Registers a callback function for when the body leaves a sensor.

Signature:

onBodyLeave: function(self: Body, callback: function(other: Body, sensorTag: integer))

Parameters:

ParameterTypeDescription
callbackfunctionThe callback function for when the body leaves a sensor.

onContactStart

Type: Function.

Description:

  Registers a callback function for when the body starts to collide with another object. This function sets the receivingContact property to true.

Signature:

onContactStart: function(self: Body, callback: function(other: Body, point: Vec2, normal: Vec2, enabled: boolean))

Parameters:

ParameterTypeDescription
callbackfunctionThe callback function for when the body starts to collide with another object.

onContactEnd

Type: Function.

Description:

  Registers a callback function for when the body stops colliding with another object. This function sets the receivingContact property to true.

Signature:

onContactEnd: function(self: Body, callback: function(other: Body, point: Vec2, normal: Vec2))

Parameters:

ParameterTypeDescription
callbackfunctionThe callback function for when the body stops colliding with another object.