API reference
Every public class, method, and event in @codexo/exojs. Generated from source.
namespaceTilemap Functions
@codexo/exojs-tilemap / tilemap / stable
Free functions and constants exported from @codexo/exojs-tilemap.
2
props
11
methods
0
events
Overview
Free functions and constants exported from @codexo/exojs-tilemap. Import any of them directly, for example `import { autoTile } from '@codexo/exojs-tilemap'`.
Functions11
autoTile(layer: TileLayerA generic, format-independent tile layer with chunk-first storage. Tile data is stored in fixed-size TileChunks indexed by signed chunk coordinates. For finite…, wangSet: WangSetDescribes a Wang autotile set: a mapping from a neighbor bitmask to a local tile ID within a specific tileset. Blob bitmask bit layout (powers of 2): - Bit 0 (…, options?: AutoTileOptionsOptions for autoTile and refreshCell.): voidApply Wang autotiling to layer using wangSet. Iterates every cell in the layer. For each cell that belongs to the Wang group, computes a neighbor bitmask and looks up the correct local tile ID from WangSet.blobMap. The layer is mutated in place; cells whose computed bitmask has no mapping in the blobMap are left unchanged. The function performs two passes (snapshot then write) so neighbor tests always reflect the pre-call state regardless of processing order. **Group membership.** With no matchFn, a cell belongs to the group when its tilesetIndex matches WangSet.tilesetIndex and its localTileId is a member of the set. Membership covers every variant the set can produce, so re-running autoTile (or refreshCell) on already-autotiled data is stable. Paint with a tile ID that is a member (a blobMap value, or one listed in WangSetOptions.members). **Blob mode bitmask (bit positions):** 1 | 2 | 4 8 | -- | 16 32 | 64 | 128 Diagonal bits (1, 4, 32, 128) are only set when both adjacent cardinals are also set (the "corner dependency" rule that reduces 256 raw combinations to 47 valid blob states). **Edge mode bitmask (bit positions):** Top=1, Right=2, Bottom=4, Left=8.
buildTileCollisionGeometry(layer: TileLayerA generic, format-independent tile layer with chunk-first storage. Tile data is stored in fixed-size TileChunks indexed by signed chunk coordinates. For finite…, options: TileCollisionOptionsOptions for buildTileCollisionGeometry.): TileCollisionGeometryCollision geometry extracted from a tile layer: whole-cell boxes merged into as few TileCollisionRects as a greedy pass can manage, plus every other shape pass…Extract collision geometry from a tile layer's per-tile import('./types').TileDefinition.collision shapes. Every placed tile in region is resolved back to its tileset definition, and each collision shape is transformed from tile-local pixel space into layer pixel space (+Y down) - applying the tile's flip/rotation transform, the tileset draw offset, and the layer's pixel offset, so the geometry lands exactly where the tile is drawn. Shapes that end up covering exactly one whole tile cell are collected into an occupancy grid and merged into as few TileCollisionRects as a greedy pass manages - a 200×200 solid region becomes one rectangle instead of 40 000. Cells only merge with neighbours whose source object carries the same type string, so a water run never fuses into an adjacent solid run. Everything else (partial boxes, ellipses, polygons, polylines, points, rotated geometry) passes through individually as a TileCollisionShape. A TileCollisionOptions.cells source feeds the same occupancy grid from outside the tiles, for collision authored per cell rather than per tile. It is consulted first, so a whole-cell tile box landing on a cell the source already claimed passes through as a shape rather than overwriting it. With a cell source and no explicit region, a bounded layer walks its full tile extent - a layer that renders nothing at all still produces geometry. This package has no physics dependency and builds no bodies: the result is plain geometry. Turning it into colliders is a short loop in application code.
createSampledChunkSource(layer: TileLayerA generic, format-independent tile layer with chunk-first storage. Tile data is stored in fixed-size TileChunks indexed by signed chunk coordinates. For finite…, options: SampledChunkSourceOptionsOptions for createSampledChunkSource.): ChunkSourceSupplies chunk data for one import('./TileLayer').TileLayer on demand, keyed by signed chunk coordinates - the abstraction a import('./ChunkStreamer').ChunkStr…Build a import('./ChunkStreamer').ChunkStreamer-ready ChunkSource from a caller-supplied sampling function - the generic mechanism behind procedurally generated tile content (noise, a heightmap, or any other per-tile-coordinate scalar function). This module intentionally has no opinion on the sampling algorithm itself (SampledChunkSourceOptions.sample/mapValueToTile are both required, not defaulted) - pick or write whatever generation function fits your game. layer supplies the target chunk grid (TileLayer.chunkWidth/ chunkHeight) and the tileset list tiles are packed against (TileLayer.tilesets) - the same TileLayer you'll construct the ChunkStreamer with.
createWorkerSampledChunkSource(layer: TileLayerA generic, format-independent tile layer with chunk-first storage. Tile data is stored in fixed-size TileChunks indexed by signed chunk coordinates. For finite…, options: WorkerSampledChunkSourceOptionsOptions for createWorkerSampledChunkSource.): ChunkSourceSupplies chunk data for one import('./TileLayer').TileLayer on demand, keyed by signed chunk coordinates - the abstraction a import('./ChunkStreamer').ChunkStr… & { destroy: unknown }Build a import('./ChunkStreamer').ChunkStreamer-ready ChunkSource that samples off the main thread via a Web Worker - the async counterpart to import('./SampledChunkSource').createSampledChunkSource, for sampling functions expensive enough to want off-thread execution. Unlike the synchronous provider, sampling logic cannot be passed as a live function - functions cannot cross a postMessage boundary. Instead WorkerSampledChunkSourceOptions.workerSource is a self-contained worker script string; see its documentation for the protocol. The returned value's destroy() MUST be called when done with it - the underlying Worker is a real resource that leaks otherwise. import('./ChunkStreamer').ChunkStreamer does not own the source it is given and never calls this for you: ChunkSource itself has no lifecycle hook, so nothing ties the two together automatically. Call it yourself alongside your own ChunkStreamer.destroy() call. workerSource runs through import('@codexo/exojs').InlineWorker, so it needs no bundler support of its own but does need a Content-Security-Policy that permits blob: in worker-src if your deployment sets one; the constructor names that cause when it is refused.
mapObjectDescriptor(object: TileMapObjectA format-independent map object. The geometry kind is the discriminant; narrow on `kind` to read shape-specific fields. Template objects are not yet represente…, layer: ObjectLayerA data-only layer of TileMapObjects - spawn points, trigger zones, collision regions, markers. Object layers are not rendered by the tile renderer; they are pa…): MapObjectDescriptorA format-neutral view of one map object, as handed to a import('./MapObjectSpawner').MapObjectFactory. The descriptor is what game code writes against: it reso…Build the MapObjectDescriptor for one object of layer. Exposed for code that spawns from a hand-picked object rather than from a whole map; mapObjectDescriptors covers the common case.
mapObjectDescriptors(map: TileMapA generic, format-independent tile map. Owns a finite grid of TileLayers and a shared set of TileSets. Tile data is stored in compact chunked arrays - no per-t…): Generator<MapObjectDescriptorA format-neutral view of one map object, as handed to a import('./MapObjectSpawner').MapObjectFactory. The descriptor is what game code writes against: it reso…>Every object of map, in a defined order: object-layer order first, then object order within each layer. This is the order a import('./MapObjectSpawner').MapObjectSpawner spawns in, so the same map always produces the same sequence.
packTile(tilesetIndex: number, localTileId: number, transform: TileTransformDescribes the orientation of a placed tile independent of source-format flip-bit encodings. The eight legal combinations map to the eight distinct 90°-rotation…): numberEncode a tileset-local tile reference and transform into a packed word. The localTileId is stored as (localTileId + 1) so that a packed value of 0 cleanly represents an empty cell, while tile 0 from tileset 0 with identity transform is stored as 1 (non-zero). Returns 0 for an empty cell. Public so chunk-provider authors (e.g. a format adapter or procedural generator) can build a ChunkPayload's tiles array without duplicating this encoding.
refreshCell(layer: TileLayerA generic, format-independent tile layer with chunk-first storage. Tile data is stored in fixed-size TileChunks indexed by signed chunk coordinates. For finite…, x: number, y: number, wangSet: WangSetDescribes a Wang autotile set: a mapping from a neighbor bitmask to a local tile ID within a specific tileset. Blob bitmask bit layout (powers of 2): - Bit 0 (…, options?: AutoTileOptionsOptions for autoTile and refreshCell.): voidIncrementally re-autotile a single cell and its eight neighbours after an edit, instead of re-running autoTile over the whole layer. A cell's blob/edge mask depends only on its immediate neighbours, so painting or erasing cell (x, y) can change the variant of that cell and of the (up to) eight cells that have it as a neighbour - but nothing further out. This recomputes exactly that 3×3 neighbourhood, touching only the 1-4 chunks it spans (and rebuilding geometry only for chunks whose tiles actually change). For a paint operation this is O(1) work versus autoTile's O(width·height). Membership is read live from the layer, so the membership test MUST be variant-stable: the default (WangSet.isMember) is, and any custom matchFn you pass must be too (see AutoTileOptions.matchFn). Typical editor use: write the painted tile with layer.setTileAt(...) using a member tile ID, then call refreshCell(layer, x, y, wangSet).
tileToChunkCoord(tx: number, ty: number, chunkW: number, chunkH: number): ChunkCoordA signed chunk coordinate pair.Convert tile coordinates to chunk coordinates given a chunk size.
tileToLocalInChunk(tx: number, ty: number, chunkW: number, chunkH: number): { lx: number; ly: number }Convert tile coordinates to local-in-chunk coordinates.
unpackTile(packed: number): null | { localTileId: number; tilesetIndex: number; transform: TileTransformDescribes the orientation of a placed tile independent of source-format flip-bit encodings. The eight legal combinations map to the eight distinct 90°-rotation… }Decode a packed word into its components. Returns null for an empty cell (packed === 0).
Constants2
The identity transform: no flip, no diagonal.
Default immutable tilemap extension descriptor. Registers the WebGL2/WebGPU tile chunk renderers (renderers) and the TileMapNode scene serializer (serializers); it carries no asset bindings - there is no generic on-disk tilemap format in this slice, so format adapters (e.g. @codexo/exojs-tiled) own loading and depend on this descriptor to pull in rendering. Install + register directly for procedural / hand-built maps (extensions: [tilemapExtension] plus a TileMap built via the runtime), or receive it transitively through a format adapter's dependencies. Pass it to the application that should have it via ApplicationOptions.extensions.