Skip to content

1681-engine / index / TilemapView

Class: TilemapView ​

Defined in: src/tilemap/TilemapView.ts:36

Draws a Tiled map's tile layers. Each layer is cut into chunks painted once into textures; a frame only toggles which chunks are in view (update), so a map of any size costs a handful of sprites a frame.

Animated tiles are drawn on their first frame.

Constructors ​

Constructor ​

ts
new TilemapView(
   stage, 
   map, 
   options?
): TilemapView;

Defined in: src/tilemap/TilemapView.ts:47

Parameters ​

ParameterType
stageStage
mapTileMap
optionsTilemapViewOptions

Returns ​

TilemapView

Properties ​

layers ​

ts
readonly layers: Map<string, Container<ContainerChild>>;

Defined in: src/tilemap/TilemapView.ts:38

One container per drawn tile layer, by name, each at its own depth among the bodies.


map ​

ts
readonly map: TileMap;

Defined in: src/tilemap/TilemapView.ts:49

Accessors ​

heightPx ​

Get Signature ​

ts
get heightPx(): number;

Defined in: src/tilemap/TilemapView.ts:122

Returns ​

number


widthPx ​

Get Signature ​

ts
get widthPx(): number;

Defined in: src/tilemap/TilemapView.ts:118

World size of the map in px.

Returns ​

number

Methods ​

destroy() ​

ts
destroy(): void;

Defined in: src/tilemap/TilemapView.ts:126

Returns ​

void


refreshTiles() ​

ts
refreshTiles(layerName, cells): void;

Defined in: src/tilemap/TilemapView.ts:94

Repaints the chunks holding these cells (row-major indices) of a drawn layer, after its data changed: a door opening, a wall dug out, a cell autotiled again (updateAutotile returns exactly the indices to pass). Costs one chunk's painting per chunk touched, so keep it out of every frame.

Parameters ​

ParameterType
layerNamestring
cellsIterable<number>

Returns ​

void


update() ​

ts
update(margin?): void;

Defined in: src/tilemap/TilemapView.ts:82

Shows only the chunks in the camera's view (plus a margin in world px). Call once a frame.

Parameters ​

ParameterTypeDefault value
marginnumber32

Returns ​

void

Released under the MIT License.