API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classTileColliderStreamer

@codexo/exojs-tilemap-physics / tilemap-physics / stable

Keeps a physics world's static tile colliders in sync with a TileLayer: one static body per chunk-sized partition of the layer, rebuilt when that partition changes, destroyed when it is evicted. The bridge owns every body it creates and nothing else. It observes the layer through its public revision counters, so it works with any chunk source - import('@codexo/exojs-tilemap').ChunkStreamer, a hand-rolled loader, or a fully resident bounded layer. Tick it from `preFrame`, before the frame's fixed steps run - not from `update`, which runs after them: ```ts const colliders = new TileColliderStreamer(world, layer); scene.systems.add({ preFrame: () => colliders.sync() }); ``` `SceneScope` runs `preFrame` once per frame, before any of that frame's fixed steps, and `update` after all of them. A chunk that becomes resident this frame needs its collider body built before the world steps over the hole, and a chunk evicted this frame must not keep its body for a whole extra frame of stepping - `update` gets both of those one step too late. Wiring `sync()` into `fixedUpdate` instead (ordered before SystemOrder.Physics) also works, and additionally re-syncs on every fixed step within a frame rather than once per frame. Two consequences worth knowing before shipping a level: - Whole-cell merging never crosses a partition boundary, so a solid run spanning two of them is at least two rectangles. This is what makes the result independent of the order chunks were loaded in. - A dynamic body resting on a chunk that gets evicted falls. Eviction is the chunk source's decision; widen its unload radius if that matters. - With TileColliderOptions.cells, a bounded layer's partitions are all covered, resident or not - collision authored per cell does not depend on tiles being placed.

1
props
3
methods
0
events
Import
import { TileColliderStreamer } from '@codexo/exojs-tilemap-physics'

Keeps a physics world's static tile colliders in sync with a TileLayer: one static body per chunk-sized partition of the layer, rebuilt when that partition changes, destroyed when it is evicted.

The bridge owns every body it creates and nothing else. It observes the layer through its public revision counters, so it works with any chunk source - import('@codexo/exojs-tilemap').ChunkStreamer, a hand-rolled loader, or a fully resident bounded layer.

Tick it from `preFrame`, before the frame's fixed steps run - not from `update`, which runs after them:

```ts const colliders = new TileColliderStreamer(world, layer); scene.systems.add({ preFrame: () => colliders.sync() }); ```

`SceneScope` runs `preFrame` once per frame, before any of that frame's fixed steps, and `update` after all of them. A chunk that becomes resident this frame needs its collider body built before the world steps over the hole, and a chunk evicted this frame must not keep its body for a whole extra frame of stepping - `update` gets both of those one step too late. Wiring `sync()` into `fixedUpdate` instead (ordered before SystemOrder.Physics) also works, and additionally re-syncs on every fixed step within a frame rather than once per frame.

Two consequences worth knowing before shipping a level:

- Whole-cell merging never crosses a partition boundary, so a solid run spanning two of them is at least two rectangles. This is what makes the result independent of the order chunks were loaded in. - A dynamic body resting on a chunk that gets evicted falls. Eviction is the chunk source's decision; widen its unload radius if that matters. - With TileColliderOptions.cells, a bounded layer's partitions are all covered, resident or not - collision authored per cell does not depend on tiles being placed.

Constructors1
Methods3
The bodies this bridge owns, in (cy, cx) partition order - independent of the order the chunks became resident in.
destroy(): void
Destroy every body this bridge created and stop responding to sync. Bodies it did not create are untouched. Idempotent.
sync(): void
Bring the world's tile colliders up to date with the layer: build bodies for newly resident chunks, rebuild edited ones, destroy evicted ones. Cheap to call every frame. With no change since the last call it performs no work and allocates nothing. No-op once destroyed or once the layer is destroyed.
Properties1
bodyCount: number
Number of bodies currently owned by this bridge.
Source