Loader#json()

json(key, url, overwrite) → {Phaser.Loader}

Adds a JSON file to the current load queue.

The file is not loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts.

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.getJSON(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 the Loader will take the key and create a filename from that. For example if the key is "alien"
and no URL is given then the Loader will set the URL to be "alien.json". It will always add .json as the extension.
If you do not desire this action then provide a URL.

Parameters
Name Type Argument Default Description
key string

Unique asset key of the json file.

url string <optional>

URL of the JSON file. If undefined or null the url will be set to <key>.json, i.e. if key was "alien" then the URL will be "alien.json".

overwrite boolean <optional>
false

If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.

Returns

This Loader instance.

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

Please login to continue.