Optionalgravity: Vec2Initial gravity vector (default (0, 0)).
Optionalbroadphase: BroadphaseBroadphase algorithm to use.
Read-only list of all active collision/fluid arbiters.
Read-only list of all Body objects directly in this space.
The broadphase algorithm currently in use.
Read-only list of all Compound objects in this space.
Read-only list of all Constraint objects in this space.
If true, the simulation produces identical results across runs on the same platform given the same inputs (same-platform "soft" determinism).
When enabled, all internal iteration orders (bodies, constraints, arbiters,
islands) are sorted by stable IDs before processing. sortContacts is also
forced to true.
Performance: adds ~1-5% overhead to step() due to sorting. Default: false.
Cumulative time simulated (sum of all deltaTime values passed to step()).
Read-only list of all event listeners registered to this space.
Read-only list of bodies that are awake and actively simulated.
Read-only list of active (awake) constraints.
Read-only snapshot of the last step() metrics.
Returns a reused object (no allocation per call). Only populated when
profilerEnabled is true; all values are zero otherwise.
Call metrics.toJSON() for a plain-object copy suitable for logging.
Enable the built-in performance profiler. When true, each step() call
measures per-phase timings (broadphase, narrowphase, velocity solver,
position solver, CCD, sleep) and collects entity counters (body, contact,
constraint counts). Read results via metrics.
Performance: adds ~14 performance.now() calls per step (~1 microsecond
total). Default: false.
If true, contact points are sorted for determinism. Default: true.
Number of sub-steps performed per step() call. Each sub-step uses
deltaTime / subSteps and the same velocity/position iteration counts.
Higher values improve simulation stability (stacking, fast objects, joint stiffness) at the cost of proportionally more CPU time.
1 (default) — standard single-step behaviour, zero overhead.4 — good balance between quality and performance for most games.8+ — high-precision, useful for stiff constraints or very fast objects.Performance: cost scales linearly — subSteps = 4 ≈ 4× solver work.
Tip: you can lower velocityIterations to compensate (e.g. 10 iter × 1 step
→ 3 iter × 4 sub-steps ≈ similar quality at ~1.2× cost).
Number of step() calls made so far.
Arbitrary user data attached to this Space.
The static world body that acts as an immovable anchor for constraints.
Return all bodies that have at least one shape overlapping the given AABB.
The axis-aligned bounding box to test against.
If true, only shapes fully contained within the AABB count.
If true, exact shape geometry is tested; otherwise only AABBs are compared.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: BodyList | nullOptional existing BodyList to accumulate results into.
A BodyList of matching bodies.
Return all bodies in the space that overlap with any shape attached to body.
Equivalent to calling bodiesInShape for each of body's shapes and merging results.
The body whose shapes are used as the query region.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: BodyList | nullOptional existing BodyList to accumulate results into.
A BodyList of overlapping bodies.
Return all bodies that have at least one shape overlapping a query circle.
World-space centre of the query circle.
Radius of the query circle; must be strictly positive and not NaN.
If true, only shapes fully contained within the circle count.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: BodyList | nullOptional existing BodyList to accumulate results into.
A BodyList of matching bodies.
Return all bodies in the space that have at least one shape overlapping shape.
The query shape; must be attached to a Body.
If true, only shapes fully contained within shape count.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: BodyList | nullOptional existing BodyList to accumulate results into.
A BodyList of overlapping bodies.
Return all bodies that have at least one shape containing the given world-space point.
The world-space point to test.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: BodyList | nullOptional existing BodyList to accumulate results into.
A BodyList of matching bodies.
Sweep shape along its current velocity for deltaTime seconds and return the first hit.
The shape to sweep; must belong to a Body.
Duration of the sweep; must be non-negative.
If true, other body velocities are considered during the sweep.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
The first RayResult hit, or null if nothing was struck.
Sweep shape along its current velocity for deltaTime seconds and return all hits.
The shape to sweep; must belong to a Body.
Duration of the sweep; must be non-negative.
If true, other body velocities are considered during the sweep.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ConvexResultList | nullOptional existing RayResultList to accumulate results into.
A RayResultList of all hits encountered during the sweep.
Draw the current state of the physics world using a user-supplied renderer.
Walks all bodies, shapes, constraints, contacts, AABBs, and velocity
vectors and calls the appropriate draw primitives on drawer. Only the
layers selected by flags are rendered.
Performance note: this method allocates temporary vertex arrays for polygon shapes on every call. It is intended for development/debug use only — do not call it in a performance-critical production loop.
The renderer to use. Must not be null.
Bitmask of DebugDrawFlags layers to render.
Defaults to DebugDrawFlags.ALL.
Determine the type of interaction between two shapes (COLLISION, FLUID, SENSOR, or null if they don't interact).
The InteractionType, or null if the shapes would not interact.
Cast a ray into the space and return the closest hit.
The ray to cast.
If true, shapes are tested from the inside as well (useful for concave queries).
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
The closest RayResult, or null if nothing was hit.
Cast a ray into the space and return all hits.
The ray to cast.
If true, shapes are tested from the inside as well.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: RayResultList | nullOptional existing RayResultList to accumulate results into.
A RayResultList of all shapes the ray intersected.
Return all shapes that overlap with the given AABB.
The axis-aligned bounding box to test against.
If true, only shapes fully contained within the AABB are returned.
If true, exact shape geometry is tested; otherwise only AABBs are compared.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ShapeList | nullOptional existing ShapeList to accumulate results into.
A ShapeList of matching shapes.
Return all shapes in the space that overlap with any shape attached to body.
Equivalent to calling shapesInShape for each of body's shapes and merging results.
The body whose shapes are used as the query region.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ShapeList | nullOptional existing ShapeList to accumulate results into.
A ShapeList of overlapping shapes.
Return all shapes that overlap with a circle defined by position and radius.
World-space centre of the query circle.
Radius of the query circle; must be strictly positive and not NaN.
If true, only shapes fully contained within the circle are returned.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ShapeList | nullOptional existing ShapeList to accumulate results into.
A ShapeList of matching shapes.
Return all shapes in the space that overlap with shape.
The query shape; must be attached to a Body.
If true, only shapes fully contained within shape are returned.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ShapeList | nullOptional existing ShapeList to accumulate results into.
A ShapeList of overlapping shapes.
Return all shapes whose geometry contains the given world-space point.
The world-space point to test.
Optionalfilter: InteractionFilter | nullOptional interaction filter to restrict results.
Optionaloutput: ShapeList | nullOptional existing ShapeList to accumulate results into.
A ShapeList of matching shapes.
Advance the simulation by deltaTime seconds.
velocityIterations and positionIterations control solver accuracy (default 10 each).
Time step in seconds; must be strictly positive and not NaN.
Number of velocity solver iterations (minimum 1).
Number of position solver iterations (minimum 1).
Returns a brief string summary of this space.
A string in the form Space(bodies=N).
Call lambda for every body in the space, including those inside compounds.
Callback invoked with each Body.
Call lambda for every compound in the space (recursively).
Callback invoked with each Compound.
Call lambda for every constraint in the space, including those inside compounds.
Callback invoked with each Constraint.
The physics world. Add bodies, shapes, and constraints, then call
step()each frame to advance the simulation.