Loader#tilemap()

tilemap(key, url, data, format) → {Phaser.Loader}

Adds a Tile Map data file to the current load queue.

Phaser can load data in two different formats: CSV and Tiled JSON.

Tiled is a free software package, specifically for creating tilemaps, and is available from http://www.mapeditor.org

You can choose to either load the data externally, by providing a URL to a json file.
Or you can pass in a JSON object or String via the data parameter.
If you pass a String the data is automatically run through JSON.parse and then immediately added to the Phaser.Cache.

If a URL is provided the file is not loaded immediately after calling this method, but is added to the load queue.

The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load.

Retrieve the file via Cache.getTilemapData(key). JSON files are automatically parsed upon load.
If you need to control when the JSON is parsed then use Loader.text instead and parse the text file as needed.

The URL can be relative or absolute. If the URL is relative the Loader.baseURL and Loader.path values will be prepended to it.

If the URL isn't specified and no data is given then the Loader will take the key and create a filename from that.
For example if the key is "level1" and no URL or data is given then the Loader will set the URL to be "level1.json".
If you set the format to be Tilemap.CSV it will set the URL to be "level1.csv" instead.

If you do not desire this action then provide a URL or data object.

Parameters
Name Type Argument Default Description
key string

Unique asset key of the tilemap data.

url string <optional>

URL of the tile map file. If undefined or null and no data is given the url will be set to <key>.json, i.e. if key was "level1" then the URL will be "level1.json".

data object | string <optional>

An optional JSON data object. If given then the url is ignored and this JSON object is used for map data instead.

format number <optional>
Phaser.Tilemap.CSV

The format of the map data. Either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.

Returns

This Loader instance.

Source code: loader/Loader.js (Line 1165)
doc_phaser
2017-02-14 10:54:35
Comments
Leave a Comment

Please login to continue.