API reference

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

N

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
Apply 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.
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.
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.
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.
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.
Encode 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.
Incrementally 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.
Decode a packed word into its components. Returns null for an empty cell (packed === 0).
Constants2
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.