BGE/Tiled

Alias: BGE.Tiled


Static Methods

resolveGid( map: BGE.Tiled.TiledMap, gid: dynamic, ): BGE.Tiled.TiledGidInfo

static

Looks up what a GID (a tile layer cell, or a tile object's gid) refers to: its tileset, its local id there, its tile entry if it has one, and its flip flags.

Tiled stores flips in a GID's top bits, so a flipped GID is above 2^31. Accepts it however it arrives: a LongInteger (as ParseJson gives it), a negative Integer, or a Double. A Float only works below 16777216 (2^24), so never for a flipped GID; bigger Floats count as empty.

Parameters

  • map (BGE.Tiled.TiledMap)
  • gid (dynamic)

Returns

  • BGE.Tiled.TiledGidInfo — invalid for an empty cell (0) or a GID no tileset has

toUnsignedGid(gid: dynamic): longinteger

static

Parameters

  • gid (dynamic)

Returns

  • longinteger

getLayer( map: BGE.Tiled.TiledMap, name: string, ): BGE.Tiled.TiledLayer

static

The first layer with this name (group layers' children included), or invalid.

Parameters

  • map (BGE.Tiled.TiledMap)
  • name (string)

Returns

  • BGE.Tiled.TiledLayer

getTileAt( map: BGE.Tiled.TiledMap, layer: BGE.Tiled.TiledLayer, col: integer, row: integer, ): BGE.Tiled.TiledGidInfo

static

What's in one cell of a tile layer. Rows count down from the top, as in Tiled.

Parameters

  • map (BGE.Tiled.TiledMap)
  • layer (BGE.Tiled.TiledLayer) — a tile layer
  • col (integer)
  • row (integer)

Returns

  • BGE.Tiled.TiledGidInfo — invalid for an empty cell or one outside the layer

getLayerCells( map: BGE.Tiled.TiledMap, layer: BGE.Tiled.TiledLayer, ): Array.<BGE.Tiled.TiledCell>

static

Every non-empty cell of a tile layer, row by row.

Parameters

  • map (BGE.Tiled.TiledMap)
  • layer (BGE.Tiled.TiledLayer) — a tile layer; invalid gives no cells

Returns

  • Array.<BGE.Tiled.TiledCell>

toWorldX( map: BGE.Tiled.TiledMap, pixelX: float, offsetX?: float, ): float

static

A Tiled pixel x as a world x.

Parameters

  • map (BGE.Tiled.TiledMap)
  • pixelX (float)
  • offsetX (float, optional, default: "0.0") — added to the result

Returns

  • float

toWorldY( map: BGE.Tiled.TiledMap, pixelY: float, offsetY?: float, ): float

static

A Tiled pixel y (+y down, from the map's top) as a world y (+y up, the map's bottom edge at 0).

Parameters

  • map (BGE.Tiled.TiledMap)
  • pixelY (float)
  • offsetY (float, optional, default: "0.0") — added to the result, e.g. to put a different row on world y 0

Returns

  • float

layerToColliderCells( map: BGE.Tiled.TiledMap, layer: BGE.Tiled.TiledLayer, propertyName?: string, ): Array.<BGE.TileMap.ColliderCell>

static

One BGE.TileMap.ColliderCell per cell whose tile has a non-empty string value for the property, tagged with that value - ready for BGE.TileMap.mergeTileColliderRuns(). Hidden layers count too, so collisions can live on a layer that isn't drawn.

Parameters

  • map (BGE.Tiled.TiledMap)
  • layer (BGE.Tiled.TiledLayer) — a tile layer
  • propertyName (string, optional, default: "\"collision\"") — a custom property set on tiles in the tileset

Returns

  • Array.<BGE.TileMap.ColliderCell>

layerToTileSpecs( map: BGE.Tiled.TiledMap, layer: BGE.Tiled.TiledLayer, options?: BGE.Tiled.TiledTileSpecOptions, ): Array.<BGE.TileMap.TileSpec>

static

One BGE.TileMap.TileSpec per non-empty cell of a tile layer, positioned the way Tiled draws it - ready for BGE.TileMap.bakeTileMapImages().

A tile bigger than a cell sits on the cell's bottom-left corner, unless its tileset's "Tile Render Size" is "Map Grid Size", which fits it to the cell (stretched, or scaled evenly and centered for the "Preserve Aspect Fit" fill mode). The tileset's tile offset and the layer's offset are applied. Flipped tiles set flipH/flipV; rotated tiles (diagonal flips) aren't supported and draw unrotated and unflipped.

A hidden layer (or one in a hidden group) gives no tiles. Opacity isn't baked in: set alpha (layer.opacity * 255) on the drawables made from them.

Tileset images are loaded here, once each per call, unless options.bitmaps (or, without it, the map's own bitmaps from AssetLoader.loadTiledMap()) has them.

Parameters

  • map (BGE.Tiled.TiledMap)
  • layer (BGE.Tiled.TiledLayer) — a tile layer
  • options (BGE.Tiled.TiledTileSpecOptions, optional, default: "{}")

Returns

  • Array.<BGE.TileMap.TileSpec>

makeTileRegion( info: BGE.Tiled.TiledGidInfo, bitmaps: roAssociativeArray, ): dynamic

static

The region of its tileset image a tile is drawn from; invalid if the image won't load.

Parameters

  • info (BGE.Tiled.TiledGidInfo)
  • bitmaps (roAssociativeArray)

Returns

  • dynamic

loadTileBitmap( path: string, bitmaps: roAssociativeArray, ): dynamic

static

The image at path, from bitmaps or loaded into it; invalid if it won't load.

Parameters

  • path (string)
  • bitmaps (roAssociativeArray)

Returns

  • dynamic

parseMapFile(filePath: string): BGE.Tiled.TiledMap

static

Loads a map saved in Tiled's JSON format (.tmj/.json), and any external .tsj tilesets it uses. Image and tileset paths are resolved relative to the file that names them.

Supported: orthogonal, finite maps; tile layers stored as an array, CSV or uncompressed base64; object, image and group layers; embedded and external JSON tilesets (spritesheets and image collections); custom properties.

Not supported (prints a [BGE.Tiled] message and returns invalid): infinite maps, isometric/staggered/hexagonal maps, compressed layer data, XML tilesets (.tsx). Object templates, animated tiles and Wang sets are ignored.

Parameters

  • filePath (string) — e.g. "pkg:/maps/level1.tmj"

Returns

  • BGE.Tiled.TiledMap — the map, or invalid

parseMapJson( json: string, baseDir: string, tilesets?: roAssociativeArray, ): BGE.Tiled.TiledMap

static

Parses a Tiled JSON map that's already in memory - see parseMapFile().

Parameters

  • json (string) — the map file's contents
  • baseDir (string) — folder (or URL) the map lives in, for resolving image and tileset paths; "" leaves them as written
  • tilesets (roAssociativeArray, optional, default: "invalid") — resolved .tsj path -> its parsed JSON (see listExternalTilesets()); when given, external tilesets come only from here instead of being read

Returns

  • BGE.Tiled.TiledMap — the map, or invalid

listExternalTilesets( json: string, baseDir: string, ): Array.<string>

static

The external .tsj tilesets a map names, resolved against baseDir, once each and in order - for loading them before parseMapJson(). XML (.tsx) tilesets are left out; parsing reports them.

Parameters

  • json (string) — the map file's contents
  • baseDir (string) — folder (or URL) the map lives in

Returns

  • Array.<string> — paths or URLs

listTiledMapImages(map: BGE.Tiled.TiledMap): Array.<string>

static

Every image a map's tilesets use (spritesheet images and image-collection tile images), once each - for loading them before layerToTileSpecs().

Parameters

  • map (BGE.Tiled.TiledMap)

Returns

  • Array.<string> — paths or URLs, as resolved by the parser

insertByFirstGid( tilesets: roArray, tileset: BGE.Tiled.TiledTileset, ): void

static

Parameters

  • tilesets (roArray)
  • tileset (BGE.Tiled.TiledTileset)

Returns

  • void

parseTilesetEntry( raw: roAssociativeArray, baseDir: string, suppliedTilesets?: dynamic, ): BGE.Tiled.TiledTileset

static

A map's tilesets entry: either a whole tileset, or {firstgid, source} pointing at a file.

Parameters

  • raw (roAssociativeArray)
  • baseDir (string)
  • suppliedTilesets (dynamic, optional, default: "invalid")

Returns

  • BGE.Tiled.TiledTileset

parseTileset( raw: roAssociativeArray, firstGid: integer, baseDir: string, ): BGE.Tiled.TiledTileset

static

Parameters

  • raw (roAssociativeArray)
  • firstGid (integer)
  • baseDir (string)

Returns

  • BGE.Tiled.TiledTileset

parseLayers( rawLayers: roArray, out: roArray, baseDir: string, offsetX: float, offsetY: float, visible: boolean, opacity: float, ): boolean

static

Appends each layer in rawLayers to out, replacing groups with their own layers (the group's offset, visibility and opacity combined into each). Returns false if a layer can't be read.

Parameters

  • rawLayers (roArray)
  • out (roArray)
  • baseDir (string)
  • offsetX (float)
  • offsetY (float)
  • visible (boolean)
  • opacity (float)

Returns

  • boolean

parseLayerData(raw: roAssociativeArray): roArray

static

A tile layer's GIDs as an array, from either a JSON array or uncompressed base64. GIDs with flip flags set are LongIntegers, matching what ParseJson gives for them.

Parameters

  • raw (roAssociativeArray)

Returns

  • roArray

parseObject(raw: roAssociativeArray): BGE.Tiled.TiledObject

static

Parameters

  • raw (roAssociativeArray)

Returns

  • BGE.Tiled.TiledObject

parsePoints(rawPoints: roArray): roArray

static

Parameters

  • rawPoints (roArray)

Returns

  • roArray

parseProperties(rawProperties: dynamic): roAssociativeArray

static

Tiled's [{name, type, value}] property list as a name -> value lookup.

Parameters

  • rawProperties (dynamic)

Returns

  • roAssociativeArray

getClass(raw: roAssociativeArray): string

static

Tiled 1.9 renamed objects' and tiles' "type" to "class".

Parameters

  • raw (roAssociativeArray)

Returns

  • string

getInt( raw: roAssociativeArray, key: string, default: integer, ): integer

static

Parameters

  • raw (roAssociativeArray)
  • key (string)
  • default (integer)

Returns

  • integer

getFloat( raw: roAssociativeArray, key: string, default: float, ): float

static

Parameters

  • raw (roAssociativeArray)
  • key (string)
  • default (float)

Returns

  • float

getString( raw: roAssociativeArray, key: string, default: string, ): string

static

Parameters

  • raw (roAssociativeArray)
  • key (string)
  • default (string)

Returns

  • string

getBool( raw: roAssociativeArray, key: string, default: boolean, ): boolean

static

Parameters

  • raw (roAssociativeArray)
  • key (string)
  • default (boolean)

Returns

  • boolean

getArray(raw: roAssociativeArray, key: string): roArray

static

Parameters

  • raw (roAssociativeArray)
  • key (string)

Returns

  • roArray

logError(message: string): void

static

Parameters

  • message (string)

Returns

  • void

logWarning(message: string): void

static

Parameters

  • message (string)

Returns

  • void

Other

TiledTile

static

Extends: roAssociativeArray

One tile's own data from a tileset: only tiles Tiled wrote an entry for (ones with a type, properties, or - in an image collection - their own image) have one.

Properties

  • id (integer) — Local id within its tileset (GID - the tileset's firstGid)
  • type (string) — Tiled's "class" (1.9+) or "type" (older); "" when unset
  • properties (roAssociativeArray) — Custom properties, name -> value
  • image (string) — Image-collection tiles only: full path to this tile's own image; "" otherwise
  • imageWidth (integer)
  • imageHeight (integer)

TiledTileset

static

Extends: roAssociativeArray

A tileset, embedded in the map or loaded from an external .tsj. Spritesheet tilesets have an image cut into a grid; image collections have no image and one image per tile.

Properties

  • firstGid (integer)
  • name (string)
  • tileCount (integer)
  • columns (integer) — 0 for an image collection
  • tileWidth (integer)
  • tileHeight (integer)
  • margin (integer)
  • spacing (integer)
  • image (string) — Full path to a spritesheet's image; "" for an image collection
  • imageWidth (integer)
  • imageHeight (integer)
  • tileOffsetX (integer) — Pixel offset to draw every tile at (Tiled's tileoffset; +y is down, as in Tiled)
  • tileOffsetY (integer)
  • tileRenderSize (string) — "tile" draws each tile at its own size; "grid" stretches it to the map's cell size
  • fillMode (string) — How a "grid"-sized tile fills its cell: "stretch", or "preserve-aspect-fit" (scaled
  • tiles (roAssociativeArray) — Local id (as a string) -> TiledTile, for tiles that have one
  • properties (roAssociativeArray)

TiledObject

static

Extends: roAssociativeArray

One placed object from an object layer. x/y are Tiled pixel coordinates (+y down): the top-left of a rectangle/ellipse/text, the position of a point, the origin of a polygon/polyline's points, and the BOTTOM-left of a tile object.

Properties

  • id (integer)
  • name (string)
  • type (string)
  • shape (string) — "rectangle", "point", "ellipse", "polygon", "polyline", "tile" or "text"
  • x (float)
  • y (float)
  • width (float)
  • height (float)
  • rotation (float) — Degrees clockwise
  • visible (boolean)
  • points (roArray) — polygon/polyline only: points relative to x/y, as {x, y} AAs
  • gid (dynamic) — tile objects only: the raw GID, flip flags included (see resolveGid()); 0 otherwise
  • properties (roAssociativeArray)

TiledLayer

static

Extends: roAssociativeArray

A layer. Group layers aren't kept: their children are listed in order with the group's offset added and its visibility combined in, so every layer is found by name.

Properties

  • id (integer)
  • type (string) — "tilelayer", "objectgroup" or "imagelayer"
  • name (string)
  • visible (boolean)
  • opacity (float)
  • offsetX (float) — Pixel offset (+y down, as in Tiled)
  • offsetY (float)
  • properties (roAssociativeArray)
  • width (integer) — tilelayer only: width x height raw GIDs, row by row (0 = empty)
  • height (integer)
  • data (roArray)
  • objects (roArray) — objectgroup only
  • image (string) — imagelayer only: full path to the image

TiledMap

static

Extends: roAssociativeArray

A parsed Tiled map - see BGE.Tiled.parseMapFile().

Properties

  • width (integer) — Size in cells
  • height (integer)
  • tileWidth (integer) — Cell size in pixels
  • tileHeight (integer)
  • backgroundColor (string) — "#rrggbb" / "#aarrggbb" as Tiled wrote it; "" when unset
  • properties (roAssociativeArray)
  • tilesets (roArray) — Sorted by firstGid
  • layers (roArray)
  • name (string) — The name it was loaded under, set by AssetLoader.loadTiledMap()
  • bitmaps (roAssociativeArray) — Image path -> roBitmap for every tileset image, set by AssetLoader.loadTiledMap();

TiledGidInfo

static

Extends: roAssociativeArray

What a GID refers to - see BGE.Tiled.resolveGid().

Properties

  • gid (integer) — The GID with its flip flags removed
  • tileset (BGE.Tiled.TiledTileset)
  • localId (integer)
  • tile (dynamic) — invalid when the tileset has no entry for this tile
  • flipH (boolean)
  • flipV (boolean)
  • flipD (boolean) — Diagonal flip (Tiled's 90-degree rotations combine this with flipH/flipV)

TiledCell

static

Extends: roAssociativeArray

One non-empty cell of a tile layer - see BGE.Tiled.getLayerCells().

Properties

  • row (integer)
  • col (integer)
  • info (BGE.Tiled.TiledGidInfo)

TiledTileSpecOptions

static

Extends: roAssociativeArray

Options for BGE.Tiled.layerToTileSpecs().

Properties

  • offsetX (float) — World units added to every tile's x
  • offsetY (float) — World units added to every tile's y
  • bitmaps (roAssociativeArray) — Image path -> roBitmap. Images already in it aren't loaded again, and the ones that get