blob2d
Version:
Typed Modular 2D Game Engine for Web
93 lines (74 loc) • 2.05 kB
Markdown
General integration with [Tiled Map Editor](https://www.mapeditor.org/) free software.
Global Tile IDs are generated by Tiled Map Editor from array of tilesets. It increments sequentially starting from the first tileset and going through them to the last one. https://doc.mapeditor.org/en/stable/reference/json-map-format/
- [TiledMapper](
- [TiledSpriteSheet](
A wrapper for searching Tiled JSON Map Format.
```ts
const level01 = require('./level-01.json');
const mapper = new TiledMapper(
map // ITiledMapJSON
);
```
```ts
// public interface
interface TiledMapper
{
public readonly tileSize: number;
// finds the first single tile (aka sprite) from
// a layer with the given name and returns a value
// of the iteratee. Otherwise, throws an error.
public querySprite<T>(
name: string,
iteratee: (
tileGID: number,
x: number,
y: number
) => T
): T
// searches layers by the given name for all single tiles
// (aka sprites) and returns array of iteratee values
public queryAllSprites<T>(
name: string,
iteratee: (
tileGID: number,
x: number,
y: number
) => T,
first?: boolean
): T[]
// searches layers by the given name for all tile
// groups and returns array of iteratee values
public queryAllTiles<T>(
name: string,
iteratee: (
tileGIDs: number[],
columns: number,
x: number,
y: number
) => T
): T[]
}
```
Provides a way to get texture from graphics assets via GID assigned by the map from tilesets.
```ts
const spritesheet = new TiledSpriteSheet(
map, // ITiledMapJSON,
tilesets, // ITiledTilesetDictionary,
resources, // IResourceDictionary
);
```
```ts
// public interface
interface TiledSpriteSheet
{
// returns texture of a tile with the given GID
public getTexture(tileGID: number): Texture;
// clears cached data
public destroy(): void;
}
```