Class: PhysicsWorld
Defined in: physics/physics-world.ts:59
A native 2D physics simulation containing RigidBody instances. Each step integrates motion, applies gravity, and detects and resolves collisions between bodies.
Constructors
Constructor
new PhysicsWorld(
options):PhysicsWorld
Defined in: physics/physics-world.ts:74
Creates a new PhysicsWorld instance.
Parameters
options
PhysicsWorldOptions = {}
The options for the world.
Returns
PhysicsWorld
Properties
gravity
gravity:
Vector2
Defined in: physics/physics-world.ts:60
Accessors
bodies
Get Signature
get bodies(): readonly
RigidBody[]
Defined in: physics/physics-world.ts:87
The bodies currently registered in this world.
Returns
readonly RigidBody[]
collisionEnds
Get Signature
get collisionEnds(): readonly
BodyCollisionPair[]
Defined in: physics/physics-world.ts:103
The pairs of bodies that stopped colliding during the most recent step.
Returns
readonly BodyCollisionPair[]
collisionStarts
Get Signature
get collisionStarts(): readonly
BodyCollisionPair[]
Defined in: physics/physics-world.ts:95
The pairs of bodies that started colliding during the most recent step.
Returns
readonly BodyCollisionPair[]
Methods
addBody()
addBody(
body):void
Defined in: physics/physics-world.ts:111
Registers a body with this world.
Parameters
body
The body to add.
Returns
void
removeBody()
removeBody(
body):void
Defined in: physics/physics-world.ts:120
Removes a body from this world.
Parameters
body
The body to remove.
Returns
void
Throws
An error if the body is not registered in this world.
step()
step(
deltaTimeInSeconds):void
Defined in: physics/physics-world.ts:136
Advances the simulation by a fixed time step: integrates velocities and positions for dynamic bodies, then detects and resolves collisions.
Parameters
deltaTimeInSeconds
number
The amount of time to step the simulation by, in seconds.
Returns
void