melonJS
    Preparing search index...

    Class BuiltinAdapter

    Default PhysicsAdapter that wraps melonJS's native SAT-based physics. Owns the active body set, the Detector, gravity, and the simulation step. Returns the legacy Body class as its body handle so existing property-based game code (body.vel.x = 5, body.isStatic = true) keeps working unchanged.

    Instantiated by default during Application construction; user code only touches this directly when explicitly wiring it via new Application(w, h, { physic: { adapter: new BuiltinAdapter() } }).

    Implements

    Index

    Constructors

    Properties

    bodies: Set<Body> = ...

    Active physics bodies in this simulation.

    capabilities: AdapterCapabilities = ...

    Advertised capabilities; user code may branch on these.

    detector: Detector

    Collision detector instance, created in init.

    gravity: Vector2d

    World gravity. Mutate to change at runtime.

    <0, 0.98>
    
    physicLabel: "builtin"

    Short adapter identifier exposed as world.physic. Lets user code branch on the active physics implementation without importing the concrete adapter class.

    Methods

    • Register a body with the simulation. Returns an opaque handle that becomes renderable.body. Each adapter chooses its own concrete body type — see the class doc for the convention.

      Prefer the declarative path. Set renderable.bodyDef and call Container.addChild(renderable) — the container auto-invokes addBody AND inserts the renderable into the world's broadphase (QuadTree) in one atomic step. Direct calls to addBody only register the body with this adapter; they do NOT add the renderable to the world's container hierarchy, so the broadphase won't return it as a collision candidate. A body registered via direct addBody without a matching addChild will integrate (velocity, forces) but never collide.

      Parameters

      Returns Body

    • Return the body's axis-aligned bounding box in renderable-local coordinates (relative to renderable.pos). Writes into the supplied out Bounds so callers can poll allocation-free each frame. Returns undefined if the renderable has no registered body.

      Used by ecosystem tooling — most notably @melonjs/debug-plugin — to visualize the body's effective collision extent. The adapter owns coordinate-system conversion: builtin Body already stores bounds in local space, matter stores them in world space and the adapter subtracts renderable.pos before writing.

      Required by the adapter contract: any adapter that registers bodies MUST implement this. The output is the canonical, local- space representation tools rely on regardless of which engine the adapter wraps.

      Parameters

      Returns Bounds | undefined

    • Return a snapshot of the body's collision shapes in renderable-local coordinates. The returned array is intended for read-only inspection (debug drawing, hit-region queries) — adapters may return a live reference for performance, so callers MUST NOT mutate it. Returns an empty array if no body.

      Pairs with getBodyAABB as the adapter-side debug surface; lets each adapter own its coordinate convention without polluting the underlying physics-engine body objects. Required by the adapter contract.

      Parameters

      Returns readonly BodyShape[]

    • Toggle a body between solid and sensor mode. A sensor still fires collision events (onCollisionStart / onCollisionActive / onCollisionEnd) but the engine does not push the bodies apart on contact — useful for one-way platforms, trigger zones, ground-snap ground assists, etc.

      Adapters without a native sensor flag emulate by toggling the collision mask between its previous value and NO_OBJECT.

      Parameters

      Returns void