Loader#atlas()

atlas(key, textureURL, atlasURL, atlasData, format) → {Phaser.Loader}

Adds a Texture Atlas file to the current load queue.

To create the Texture Atlas you can use tools such as:

Texture Packer
Shoebox

If using Texture Packer we recommend you enable "Trim sprite names".
If your atlas software has an option to "rotate" the resulting frames, you must disable it.

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 atlasData parameter.
If you pass a String the data is automatically run through JSON.parse and then immediately added to the Phaser.Cache.

If URLs are provided the files are not loaded immediately after calling this method, but are 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.getImage(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 JSON file as needed.

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

If the textureURL isn't specified then the Loader will take the key and create a filename from that.
For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png".
The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will
set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json".

If you do not desire this action then provide URLs and / or a data object.

Parameters
Name Type Argument Description
key string

Unique asset key of the texture atlas file.

textureURL string <optional>

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

atlasURL string <optional>

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

atlasData object <optional>

A JSON or XML data object. You don't need this if the data is being loaded from a URL.

format number <optional>

The format of the data. Can be Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY (the default), Phaser.Loader.TEXTURE_ATLAS_JSON_HASH or Phaser.Loader.TEXTURE_ATLAS_XML_STARLING.

Returns

This Loader instance.

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

Please login to continue.