Skip to content

TilemapComponent

Defined in: tilemap/src/TilemapComponent.ts:51

Component that renders a Tiled map using @pixi/tilemap.

  • Component

new TilemapComponent(options): TilemapComponent

Defined in: tilemap/src/TilemapComponent.ts:65

TilemapComponentOptions

TilemapComponent

Component.constructor

readonly container: Container

Defined in: tilemap/src/TilemapComponent.ts:52


readonly data: TilemapData

Defined in: tilemap/src/TilemapComponent.ts:53


enabled: boolean

Defined in: core/dist/index.d.ts:1731

Whether this component is active. Disabled components are skipped by ComponentUpdateSystem.

Component.enabled


entity: Entity

Defined in: core/dist/index.d.ts:1729

Back-reference to the owning entity. Set by the engine when the component is added to an entity. Do not set manually.

Component.entity


readonly keyPrefix: string | null

Defined in: tilemap/src/TilemapComponent.ts:57

Prefix used to derive auto-keys for entities spawned from objects.


readonly mapKey: string | null

Defined in: tilemap/src/TilemapComponent.ts:55

Asset path of this map, or null if constructed from a raw TiledMapData without one.

get context(): EngineContext

Defined in: core/dist/index.d.ts:1744

Access the EngineContext from the entity’s scene. Throws if the entity is not in a scene.

EngineContext

Component.context


get heightPx(): number

Defined in: tilemap/src/TilemapComponent.ts:157

Map height in pixels.

number


get scene(): Scene

Defined in: core/dist/index.d.ts:1739

Access the entity’s scene. Throws if the entity is not in a scene. Prefer this over threading through this.entity.scene in component code.

Scene

Component.scene


get tileHeight(): number

Defined in: tilemap/src/TilemapComponent.ts:167

Tile height in pixels.

number


get tileWidth(): number

Defined in: tilemap/src/TilemapComponent.ts:162

Tile width in pixels.

number


get widthPx(): number

Defined in: tilemap/src/TilemapComponent.ts:152

Map width in pixels.

number

_runCleanups(): void

Defined in: core/dist/index.d.ts:1785

Internal

Run and clear all registered cleanups. Called by Entity.remove() and Entity._performDestroy() before onRemove/onDestroy.

void

Component._runCleanups


protected addCleanup(fn): void

Defined in: core/dist/index.d.ts:1779

Register a cleanup function to run when this component is removed or destroyed.

() => void

void

Component.addCleanup


optional afterRestore(data, resolve): void

Defined in: core/dist/index.d.ts:1799

Called after onAdd() during save/load restoration. Apply state that depends on onAdd() having run.

unknown

SnapshotResolver

void

Component.afterRestore


findObject(id): MapObject | undefined

Defined in: tilemap/src/TilemapComponent.ts:282

Find an object by its Tiled id. Searches every object layer.

number

MapObject | undefined


findObjectByName(name): MapObject | undefined

Defined in: tilemap/src/TilemapComponent.ts:292

Find the first object with a matching name. Searches every object layer.

string

MapObject | undefined


optional fixedUpdate(dt): void

Defined in: core/dist/index.d.ts:1795

Called every fixed timestep by the built-in ComponentUpdateSystem.

number

void

Component.fixedUpdate


forEachObject(layerName, fn): void

Defined in: tilemap/src/TilemapComponent.ts:252

Iterate every object on the given layer (or every layer if omitted), passing the auto-derived stable key alongside each object so callers can spawn entities with scene.spawn(Class, params, { key }).

Skips objects that don’t have a key prefix (component constructed from raw map: without mapKey or keyPrefix) — those callers should iterate getObjects directly.

string | undefined

(obj, key) => void

void


getAllObjects(): MapObject[]

Defined in: tilemap/src/TilemapComponent.ts:233

Flat list of every object across every object layer. Memoized — safe because parsed map data is immutable post-construction.

MapObject[]


getCollisionShapes(objectLayerName?): TilemapColliderConfig[]

Defined in: tilemap/src/TilemapComponent.ts:207

Extract physics-agnostic collision shapes from object layers.

string

TilemapColliderConfig[]


getObjects(objectLayerName?): Record<string, MapObject[]>

Defined in: tilemap/src/TilemapComponent.ts:212

Objects from object layers grouped by class ?? name. Use a layer name to scope.

string

Record<string, MapObject[]>


getProperty<T>(obj, name): T | undefined

Defined in: tilemap/src/TilemapComponent.ts:302

Read a typed custom property off any tilemap object.

T = unknown

MapObject

string

T | undefined


getPropertyArray<T>(obj, name): T[]

Defined in: tilemap/src/TilemapComponent.ts:307

Read an indexed property bag (name[0], name[1], …) as an array.

T = unknown

MapObject

string

T[]


getTileAt(worldX, worldY, layerName?): number | null

Defined in: tilemap/src/TilemapComponent.ts:175

Returns the tile GID at a world position, accounting for entity Transform offset. Returns null if the position is outside the map or the tile is empty.

number

number

string

number | null


protected listen<T>(entity, token, handler): void

Defined in: core/dist/index.d.ts:1771

Subscribe to events on any entity, auto-unsubscribe on removal.

T

Entity

EventToken<T>

(data) => void

void

Component.listen


protected listenScene<T>(token, handler): void

Defined in: core/dist/index.d.ts:1777

Subscribe to scene-level events, auto-unsubscribe on removal. Handlers fire for bubbled entity events (entity = source) and scene.emit events (entity = undefined).

T

EventToken<T>

(data, entity?) => void

void

Component.listenScene


objectKey(obj): string

Defined in: tilemap/src/TilemapComponent.ts:272

Auto-derived stable key for an object: <keyPrefix>#object:<id>.

MapObject

string


onAdd(): void

Defined in: tilemap/src/TilemapComponent.ts:109

Called when the component is added to an entity.

void

Component.onAdd


onDestroy(): void

Defined in: tilemap/src/TilemapComponent.ts:119

Called when the component is destroyed (entity destroyed or component removed).

void

Component.onDestroy


optional onRemove(): void

Defined in: core/dist/index.d.ts:1789

Called when the component is removed from an entity.

void

Component.onRemove


resolveRef(obj, propName): MapObject | undefined

Defined in: tilemap/src/TilemapComponent.ts:315

Resolve a Tiled object-reference property to the actual object. Auto-collects across every layer so callers don’t have to.

MapObject

string

MapObject | undefined


resolveRefArray(obj, propName): MapObject[]

Defined in: tilemap/src/TilemapComponent.ts:320

Same as resolveRef, but for indexed object-reference arrays.

MapObject

string

MapObject[]


serialize(): TilemapComponentData | null

Defined in: tilemap/src/TilemapComponent.ts:124

Return a JSON-serializable snapshot of this component’s state. Used by the save system.

TilemapComponentData | null

Component.serialize


protected service<T>(key): T

Defined in: core/dist/index.d.ts:1761

Lazy proxy-based service resolution. Can be used at field-declaration time:

readonly input = this.service(InputManagerKey);

The actual resolution is deferred until first property access.

T extends object

ServiceKey<T>

T

Component.service


protected sibling<C>(cls): C

Defined in: core/dist/index.d.ts:1769

Lazy proxy-based sibling component resolution. Can be used at field-declaration time:

readonly anim = this.sibling(AnimatedSpriteComponent);

The actual resolution is deferred until first property access.

C extends Component

ComponentClass<C>

C

Component.sibling


optional update(dt): void

Defined in: core/dist/index.d.ts:1793

Called every frame by the built-in ComponentUpdateSystem.

number

void

Component.update


protected use<T>(key): T

Defined in: core/dist/index.d.ts:1752

Resolve a service by key, cached after first lookup. Scene-scoped values (registered via scene._registerScoped) take precedence over engine scope. A key declared with scope: "scene" that falls back to engine scope emits a one-shot dev warning — almost always signals a missed beforeEnter hook.

T

ServiceKey<T>

T

Component.use


static fromSnapshot(data): TilemapComponent

Defined in: tilemap/src/TilemapComponent.ts:142

TilemapComponentData

TilemapComponent