Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Body<UserData>

The bodies have position, angle, velocity. You can apply forces, impulses and add the shapes to the bodies. The bodies can be dynamic, static or kinematic.

A dynamic bodies normally move according to forces but can be moved manually by the user. Dynamic bodies collide with all body types. You can set the mass of the dynamic bodies, but it can't be zero.

A static bodies do not respond to forces and can't be moved by other bodies and behaves as if it has infinite mass. Static bodies do not collide with other static and kinematic bodies.

A kinematic bodies do not respond to forces and can't be moved by other bodies and behaves as if it has infinite mass. Kinematic can be moved by setting its velocity. Kinematic bodies do not collide with other kinematic and static bodies.

Events:

  • add-shape
  • remove-shape
  • become-dynamic
  • become-static
  • become-kinematic
  • sleep-start
  • sleep-end

Type parameters

  • UserData = any

Hierarchy

Index

Constructors

constructor

  • new Body<UserData>(options?: BodyOptions, userData?: UserData): Body<UserData>

Properties

angle

angle: number = 0

Current angle of the body.

angularVelocity

angularVelocity: number = 0

An angular velocity of the body.

area

area: number = 0

The sum of areas of all shapes attached to the body.

canSleep

canSleep: boolean = true

A variable which determines the body's ability to sleep

center

center: Vector = ...

A center mass of the body.

id

id: number = ...

An id of the body

inertia

inertia: number = 0

The moment of inertia of the body. This determines how hard it is to rotate the body.

inverseInertia

inverseInertia: number = 0

A number equal to 1 / body.inertia.

inverseMass

inverseMass: number = 0

A number equal to 1 / body.mass.

joints

joints: Set<Joint<any>> = ...

A Set of all joints attached to the body

mass

mass: number = 0

The sum of masses of all shapes attached to the body.

position

position: Vector = ...

Vector relative to which the shapes are attached.

shapes

shapes: Set<Shape<any>> = ...

Set of shapes attached to the body.

sleepState

sleepState: SleepingState = ...

Current sleeping state of the body(awake, sleepy, of sleeping)

type

type: BodyType = ...

A type of the body(dynamic, static or kinematic).

Optional userData

userData: UserData

A variable that contains user data

velocity

velocity: Vector = ...

A linear velocity of the body.

velocityDamping

velocityDamping: number = 0

A number that determines how fast the body slows down. Must be in range 0...1.

Methods

addShape

applyForce

  • applyForce(delta: number, force: Vector, offset?: Vector): void
  • Applies the given force to a body from the given offset(including resulting torque).

    Parameters

    Returns void

applyImpulse

  • Applies the given impulse to a body from the given offset(including resulting angularVelocity).

    Parameters

    Returns void

clear

  • clear(): void

off

  • off(id: number): boolean
  • Unsubscribes the callback function from the given event name.

    Parameters

    • id: number

    Returns boolean

    True if the event was successfully unsubscribed, otherwise false

on

  • on(name: string, callback: (...args: any[]) => void): number
  • Subscribes the callback function to the given event name.

    Parameters

    • name: string
    • callback: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns number

    The id of the event

once

  • once(name: string, callback: (...args: any[]) => void): void
  • Subscribes the callback function to the given event name for one time.

    Parameters

    • name: string
    • callback: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

removeShape

rotate

  • rotate(angle: number): void
  • Rotates the body by the given angle.

    Parameters

    • angle: number

    Returns void

set

setAbilityToSleep

  • setAbilityToSleep(value: boolean): void
  • Sets body.canSleep to the given value. If necessary awakens a body.

    Parameters

    • value: boolean

    Returns void

setAngle

  • setAngle(angle: number): void
  • Sets the angle of the body to the given.

    Parameters

    • angle: number

    Returns void

setFixedRotation

  • setFixedRotation(value: boolean): void
  • Sets the body's ability to rotate to the given value.

    Parameters

    • value: boolean

    Returns void

setPosition

  • setPosition(position: Vector): void
  • Sets the position of the body to the given.

    Parameters

    Returns void

setSleepingState

setType

setVelocity

  • setVelocity(velocity: Vector): void
  • Sets the velosity of a body to the given.

    Parameters

    Returns void

translate

  • translate(vector: Vector): void

trigger

  • trigger(name: string, args?: any[]): void
  • Triggers all the callbacks subscribed to the given name.

    Parameters

    • name: string
    • args: any[] = []

    Returns void

updateArea

  • updateArea(): void

updateCenterOfMass

  • updateCenterOfMass(): void
  • Updates the center of mass of the body.

    Returns void

updateInertia

  • updateInertia(): void

updateMass

  • updateMass(): void

updatePosition

  • updatePosition(): void

updateVelocity

  • updateVelocity(delta: number, gravity: Vector): void
  • Updates velocity of the body.

    Parameters

    • delta: number

      The delta time

    • gravity: Vector

    Returns void

Generated using TypeDoc