Class: Loader

Phaser. Loader

new Loader(game)

The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.

The loader uses a combination of tag loading (eg. Image elements) and XHR and provides progress and completion callbacks.

Parallel loading (see enableParallel) is supported and enabled by default. Load-before behavior of parallel resources is controlled by synchronization points as discussed in withSyncPoint.

Texture Atlases can be created with tools such as Texture Packer and Shoebox

Parameters:
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source:
src/loader/Loader.js line 21

Members

<static> mediaTypes : object

Mapping of file extensions to media types.

Type:
  • object
Source:
src/loader/Loader.js line 340

<static, constant> PHYSICS_LIME_CORONA_JSON : number

Type:
  • number
Source:
src/loader/Loader.js line 320

<static, constant> PHYSICS_PHASER_JSON : number

Type:
  • number
Source:
src/loader/Loader.js line 326

<static, constant> TEXTURE_ATLAS_JSON_ARRAY : number

Type:
  • number
Source:
src/loader/Loader.js line 302

<static, constant> TEXTURE_ATLAS_JSON_HASH : number

Type:
  • number
Source:
src/loader/Loader.js line 308

<static, constant> TEXTURE_ATLAS_JSON_PYXEL : number

Type:
  • number
Source:
src/loader/Loader.js line 332

<static, constant> TEXTURE_ATLAS_XML_STARLING : number

Type:
  • number
Source:
src/loader/Loader.js line 314

_withSyncPointDepth : integer

A counter: if more than zero, files will be automatically added as a synchronization point.

Type:
  • integer
Source:
src/loader/Loader.js line 226

baseURL : string

If you want to append a URL before the path of any asset you can set this here. Useful if allowing the asset base url to be configured outside of the game code. The string must end with a "/".

Type:
  • string
Source:
src/loader/Loader.js line 82

<protected> cache : Phaser.Cache

Local reference to the Phaser.Cache.

Type:
Source:
src/loader/Loader.js line 35

crossOrigin : boolean | string

The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'.

Type:
  • boolean | string
Source:
src/loader/Loader.js line 73

enableParallel : boolean

If true (the default) then parallel downloading will be enabled.

To disable all parallel downloads this must be set to false prior to any resource being loaded.

Type:
  • boolean
Source:
src/loader/Loader.js line 209

<protected> game : Phaser.Game

Local reference to game.

Type:
Source:
src/loader/Loader.js line 28

hasLoaded : boolean

True if all assets in the queue have finished loading.

Type:
  • boolean
Source:
src/loader/Loader.js line 56

headers : object

Used to map the application mime-types to to the Accept header in XHR requests. If you don't require these mappings, or they cause problems on your server, then remove them from the headers object and the XHR request will not try to use them.

This object can also be used to set the X-Requested-With header to XMLHttpRequest (or any other value you need). To enable this do:

this.load.headers.requestedWith = 'XMLHttpRequest'

before adding anything to the Loader. The XHR loader will then call:

setRequestHeader('X-Requested-With', this.headers['requestedWith'])
Type:
  • object
Default Value:
  • {"requestedWith":false,"json":"application/json","xml":"application/xml"}
Source:
src/loader/Loader.js line 127

isLoading : boolean

True if the Loader is in the process of loading the queue.

Type:
  • boolean
Source:
src/loader/Loader.js line 49

maxParallelDownloads : integer

The number of concurrent / parallel resources to try and fetch at once.

Many current browsers limit 6 requests per domain; this is slightly conservative.

This should generally be left at the default, but can be set to a higher limit for specific use-cases. Just be careful when setting large values as different browsers could behave differently.

Type:
  • integer
Source:
src/loader/Loader.js line 220

onBeforeLoadComplete : Phaser.Signal

This event is dispatched when the final file in the load queue has either loaded or failed, before onLoadComplete and before the loader is reset.

Type:
Source:
src/loader/Loader.js line 147

onFileComplete : Phaser.Signal

This event is dispatched when a file has either loaded or failed to load.

Any function bound to this will receive the following parameters:

progress, file key, success?, total loaded files, total files

Where progress is a number between 1 and 100 (inclusive) representing the percentage of the load.

Type:
Source:
src/loader/Loader.js line 189

onFileError : Phaser.Signal

This event is dispatched when a file (or pack) errors as a result of the load request.

For files it will be triggered before onFileComplete. For packs it will be triggered before onPackComplete.

Params: (file key, file)

Type:
Source:
src/loader/Loader.js line 200

onFileStart : Phaser.Signal

This event is dispatched immediately before a file starts loading. It's possible the file may fail (eg. download error, invalid format) after this event is sent.

Params: (progress, file key, file url)

Type:
Source:
src/loader/Loader.js line 176

onLoadComplete : Phaser.Signal

This event is dispatched when the final file in the load queue has either loaded or failed, after the loader is reset.

Type:
Source:
src/loader/Loader.js line 155

onLoadStart : Phaser.Signal

This event is dispatched when the loading process starts: before the first file has been requested, but after all the initial packs have been loaded.

Type:
Source:
src/loader/Loader.js line 139

onPackComplete : Phaser.Signal

This event is dispatched when an asset pack has either loaded or failed to load.

This is called when the asset pack manifest file has loaded and successfully added its contents to the loader queue.

Params: (pack key, success?, total packs loaded, total packs)

Type:
Source:
src/loader/Loader.js line 166

path : string

The value of path, if set, is placed before any relative file path given. For example:

load.path = "images/sprites/";
load.image("ball", "ball.png");
load.image("tree", "level1/oaktree.png");
load.image("boom", "http://server.com/explode.png");

Would load the ball file from images/sprites/ball.png and the tree from images/sprites/level1/oaktree.png but the file boom would load from the URL given as it's an absolute URL.

Please note that the path is added before the filename but after the baseURL (if set.)

The string must end with a "/".

Type:
  • string
Source:
src/loader/Loader.js line 104

<protected> preloadSprite : object

You can optionally link a progress sprite with setPreloadSprite.

This property is an object containing: sprite, rect, direction, width and height

Type:
  • object
Source:
src/loader/Loader.js line 66

progress

The rounded load progress percentage value (from 0 to 100). See Phaser.Loader#progressFloat.

Properties:
Type Description
integer
Source:
src/loader/Loader.js line 3360

progressFloat

The non-rounded load progress value (from 0.0 to 100.0).

A general indicator of the progress. It is possible for the progress to decrease, after onLoadStart, if more files are dynamically added.

Properties:
Type Description
number
Source:
src/loader/Loader.js line 3341

resetLocked : boolean

If true all calls to Loader.reset will be ignored. Useful if you need to create a load queue before swapping to a preloader state.

Type:
  • boolean
Source:
src/loader/Loader.js line 42

Methods

<static> getMediaType(url)

Guess a media type for an URL.

Parameters:
Name Type Description
url string
Source:
src/loader/Loader.js line 355
Returns:
Type
string

addSyncPoint(type, key)

Add a synchronization point to a specific file/asset in the load queue.

This has no effect on already loaded assets.

Parameters:
Name Type Description
type string

The type of resource to turn into a sync point (image, audio, xml, etc).

key string

Key of the file you want to turn into a sync point.

Source:
src/loader/Loader.js line 1955
See:
Returns:

This Loader instance.

Type
Phaser.Loader

<protected> addToFileList(type, key [, url] [, properties] [, overwrite] [, extension])

Internal function that adds a new entry to the file list. Do not call directly.

Parameters:
Name Type Argument Default Description
type string

The type of resource to add to the list (image, audio, xml, etc).

key string

The unique Cache ID key of this resource.

url string <optional>

The URL the asset will be loaded from.

properties object <optional>
(none)

Any additional properties needed to load the file. These are added directly to the added file object and overwrite any defaults.

overwrite boolean <optional>
false

If true then this will overwrite a file asset of the same type/key. Otherwise it will only add a new asset. If overwrite is true, and the asset is already being loaded (or has been loaded), then it is appended instead.

extension string <optional>

If no URL is given the Loader will sometimes auto-generate the URL based on the key, using this as the extension.

Source:
src/loader/Loader.js line 564
Returns:

This instance of the Phaser Loader.

Type
Phaser.Loader

atlas(key [, textureURL] [, atlasURL] [, atlasData] [, format])

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.

Source:
src/loader/Loader.js line 1823
Returns:

This Loader instance.

Type
Phaser.Loader

atlasJSONArray(key [, textureURL] [, atlasURL] [, atlasData])

Adds a Texture Atlas file to the current load queue.

Unlike Loader.atlasJSONHash this call expects the atlas data to be in a JSON Array format.

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 data object. You don't need this if the data is being loaded from a URL.

Source:
src/loader/Loader.js line 1680
Returns:

This Loader instance.

Type
Phaser.Loader

atlasJSONHash(key [, textureURL] [, atlasURL] [, atlasData])

Adds a Texture Atlas file to the current load queue.

Unlike Loader.atlas this call expects the atlas data to be in a JSON Hash format.

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 data object. You don't need this if the data is being loaded from a URL.

Source:
src/loader/Loader.js line 1725
Returns:

This Loader instance.

Type
Phaser.Loader

atlasXML(key [, textureURL] [, atlasURL] [, atlasData])

Adds a Texture Atlas file to the current load queue.

This call expects the atlas data to be in the Starling XML data format.

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 an xml file. Or you can pass in an XML object or String via the atlasData parameter. If you pass a String the data is automatically run through Loader.parseXML 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). XML files are automatically parsed upon load. If you need to control when the XML is parsed then use Loader.text instead and parse the XML 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.xml".

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.xml".

atlasData object <optional>

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

Source:
src/loader/Loader.js line 1770
Returns:

This Loader instance.

Type
Phaser.Loader

audio(key, urls [, autoDecode])

Adds an audio 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.getSound(key).

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

Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio. When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system. The solution is to use a lower encoding rate such as 44100 Hz.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the audio file.

urls string | Array.<string> | Array.<object>

Either a single string or an array of URIs or pairs of {uri: .., type: ..}. If an array is specified then the first URI (or URI + mime pair) that is device-compatible will be selected. For example: "jump.mp3", ['jump.mp3', 'jump.ogg', 'jump.m4a'], or [{uri: "data:<opus_resource>", type: 'opus'}, 'fallback.mp3']. BLOB and DATA URIs can be used but only support automatic detection when used in the pair form; otherwise the format must be manually checked before adding the resource.

autoDecode boolean <optional>
true

When using Web Audio the audio files can either be decoded at load time or run-time. Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially.

Source:
src/loader/Loader.js line 1246
Returns:

This Loader instance.

Type
Phaser.Loader

audioSprite(key, urls [, jsonURL] [, jsonData] [, autoDecode])

Adds an audio sprite 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.

Audio Sprites are a combination of audio files and a JSON configuration.

The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite

Retrieve the file via Cache.getSoundData(key).

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

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the audio file.

urls Array | string

An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL.

jsonURL string <optional>
null

The URL of the audiosprite configuration JSON object. If you wish to pass the data directly set this parameter to null.

jsonData string | object <optional>
null

A JSON object or string containing the audiosprite configuration data. This is ignored if jsonURL is not null.

autoDecode boolean <optional>
true

When using Web Audio the audio files can either be decoded at load time or run-time. Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially.

Source:
src/loader/Loader.js line 1288
Returns:

This Loader instance.

Type
Phaser.Loader

audiosprite(key, urls [, jsonURL] [, jsonData] [, autoDecode])

A legacy alias for Loader.audioSprite. Please see that method for documentation.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the audio file.

urls Array | string

An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL.

jsonURL string <optional>
null

The URL of the audiosprite configuration JSON object. If you wish to pass the data directly set this parameter to null.

jsonData string | object <optional>
null

A JSON object or string containing the audiosprite configuration data. This is ignored if jsonURL is not null.

autoDecode boolean <optional>
true

When using Web Audio the audio files can either be decoded at load time or run-time. Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially.

Source:
src/loader/Loader.js line 1346
Returns:

This Loader instance.

Type
Phaser.Loader

binary(key [, url] [, callback] [, callbackContext])

Adds a binary 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.getBinary(key).

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.bin". It will always add .bin as the extension. If you do not desire this action then provide a URL.

It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load. When the callback is called it will be passed 2 parameters: the key of the file and the file data.

WARNING: If a callback is specified the data will be set to whatever it returns. Always return the data object, even if you didn't modify it.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the binary file.

url string <optional>

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

callback function <optional>
(none)

Optional callback that will be passed the file after loading, so you can perform additional processing on it.

callbackContext object <optional>

The context under which the callback will be applied. If not specified it will use the callback itself as the context.

Source:
src/loader/Loader.js line 1144
Returns:

This Loader instance.

Type
Phaser.Loader

bitmapFont(key, textureURL, atlasURL, atlasData [, xSpacing] [, ySpacing])

Adds Bitmap Font files to the current load queue.

To create the Bitmap Font files you can use:

BMFont (Windows, free): http://www.angelcode.com/products/bmfont/ Glyph Designer (OS X, commercial): http://www.71squared.com/en/glyphdesigner Littera (Web-based, free): http://kvazars.com/littera/

You can choose to either load the data externally, by providing a URL to an xml file. Or you can pass in an XML object or String via the xmlData parameter. If you pass a String the data is automatically run through Loader.parseXML 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.getBitmapFont(key). XML files are automatically parsed upon load. If you need to control when the XML is parsed then use Loader.text instead and parse the XML 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 "megaFont" and textureURL is null then the Loader will set the URL to be "megaFont.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 "megaFont" the atlasURL will be set to "megaFont.xml".

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

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the bitmap font.

textureURL string

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

atlasURL string

URL of the Bitmap Font atlas file (xml/json). If undefined or null AND atlasData is null, the url will be set to <key>.xml, i.e. if key was "megaFont" then the URL will be "megaFont.xml".

atlasData object

An optional Bitmap Font atlas in string form (stringified xml/json).

xSpacing number <optional>
0

If you'd like to add additional horizontal spacing between the characters then set the pixel value here.

ySpacing number <optional>
0

If you'd like to add additional vertical spacing between the lines then set the pixel value here.

Source:
src/loader/Loader.js line 1588
Returns:

This Loader instance.

Type
Phaser.Loader

checkKeyExists(type, key)

Check whether a file/asset with a specific key is queued to be loaded.

To access a loaded asset use Phaser.Cache, eg. Phaser.Cache#checkImageKey

Parameters:
Name Type Description
type string

The type asset you want to check.

key string

Key of the asset you want to check.

Source:
src/loader/Loader.js line 443
Returns:

Return true if exists, otherwise return false.

Type
boolean

getAsset(type, key)

Find a file/asset with a specific key.

Only assets in the download file queue will be found.

Parameters:
Name Type Description
type string

The type asset you want to check.

key string

Key of the asset you want to check.

Source:
src/loader/Loader.js line 492
Returns:

Returns an object if found that has 2 properties: index and file; otherwise a non-true value is returned. The index may change and should only be used immediately following this call.

Type
any

getAssetIndex(type, key)

Get the queue-index of the file/asset with a specific key.

Only assets in the download file queue will be found.

Parameters:
Name Type Description
type string

The type asset you want to check.

key string

Key of the asset you want to check.

Source:
src/loader/Loader.js line 458
Returns:

The index of this key in the filelist, or -1 if not found. The index may change and should only be used immediately following this call

Type
number

image(key [, url] [, overwrite])

Adds an Image 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.

Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle.

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

Retrieve the image via Cache.getImage(key).

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.png". It will always add .png as the extension. If you do not desire this action then provide a URL.

Compressed Textures

This method also supports passing in a texture object as the url argument. This allows you to load compressed textures into Phaser. You can also use Loader.texture to do this.

Compressed Textures are a WebGL only feature, and require 3rd party tools to create. Available tools include Texture Packer, PVRTexTool, DirectX Texture Tool and Mali Texture Compression Tool.

Supported texture compression formats are: PVRTC, S3TC and ETC1. Supported file formats are: PVR, DDS, KTX and PKM.

The formats that support all 3 compression algorithms are PVR and KTX. PKM only supports ETC1, and DDS only S3TC for now.

The texture path object looks like this:

load.image('factory', {
    etc1: 'assets/factory_etc1.pkm',
    s3tc: 'assets/factory_dxt1.pvr',
    pvrtc: 'assets/factory_pvrtc.pvr',
    truecolor: 'assets/factory.png'
});

The truecolor property points to a standard PNG file, that will be used if none of the compressed formats are supported by the browser / GPU.

Multiple Image Sources

You can pass an array url argument to load one of several alternative image sources. The browser will choose its preferred source. You can also use Loader.imageset to do this.

load.image('flower', [
    'flower.avif',
    'flower.webp',
    'flower.png'
]);

You can also describe the media types explicitly:

load.image('flower', [
    { url: 'flower.avif', type: 'image/avif' },
    { url: 'flower.webp', type: 'image/webp' },
    { url: 'flower.png', type: 'image/png' }
]);
Parameters:
Name Type Argument Default Description
key string

Unique asset key of this image file.

url string | object | Array.<string> | Array.<object> <optional>

URL of an 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". Can also be a texture data object or a source array.

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 741
Returns:

This Loader instance.

Type
Phaser.Loader

imageFromBitmapData(key, bitmapData [, overwrite])

Generate an image from a BitmapData object and add it to the current load queue.

Parameters:
Name Type Argument Default Description
key string

Unique asset key for the generated image.

bitmapData Phaser.BitmapData
overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 852
Returns:

This Loader instance.

Type
Phaser.Loader

imageFromGrid()

Generate a grid image and add it to the current load queue.

Source:
src/loader/Loader.js line 866
See:

imageFromTexture()

Generate a texture image and add it to the current load queue.

Source:
src/loader/Loader.js line 877
See:

images(keys [, urls])

Adds an array of images to the current load queue.

It works by passing each element of the array to the Loader.image method.

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

Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle.

The keys must be unique Strings. They are used to add the files to the Phaser.Cache upon successful load.

Retrieve the images via Cache.getImage(key)

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.png". It will always add .png as the extension. If you do not desire this action then provide a URL.

Parameters:
Name Type Argument Description
keys array

An array of unique asset keys of the image files.

urls array <optional>

Optional array of URLs. 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". If provided the URLs array length must match the keys array length.

Source:
src/loader/Loader.js line 961
Returns:

This Loader instance.

Type
Phaser.Loader

imageset(key [, sources] [, overwrite])

Adds an Image to the current load queue, giving several alternative sources. The browser will choose its preferred source.

Sources can be URLs or objects in the form { url, type }, where type is the media type. If the source is an URL (string) then Phaser will guess the media type.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of this image file.

sources Array.<string> | Array.<object> <optional>

Source URLs or objects in the form { url, type }.

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 831
Returns:

This Loader instance.

Type
Phaser.Loader

json(key [, url] [, overwrite])

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.

Source:
src/loader/Loader.js line 1031
Returns:

This Loader instance.

Type
Phaser.Loader

pack(key [, url] [, data] [, callbackContext])

Add a JSON resource pack ('packfile') to the Loader.

A packfile is a JSON file that contains a list of assets to the be loaded. Please see the example 'loader/asset pack' in the Phaser Examples repository.

Packs are always put before the first non-pack file that is not loaded / loading.

This means that all packs added before any loading has started are added to the front of the file queue, in the order added.

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

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

Parameters:
Name Type Argument Default Description
key string

Unique asset key of this resource pack.

url string <optional>

URL of the Asset Pack JSON file. If you wish to pass a json object instead set this to null and pass the object as the data parameter.

data object <optional>

The Asset Pack JSON data. Use this to pass in a json data object rather than loading it from a URL. TODO

callbackContext object <optional>
(loader)

Some Loader operations, like Binary and Script require a context for their callbacks. Pass the context here.

Source:
src/loader/Loader.js line 660
Returns:

This Loader instance.

Type
Phaser.Loader

physics(key [, url] [, data] [, format])

Adds a physics data file to the current load queue.

The data must be in Lime + Corona JSON format. Physics Editor by code'n'web exports in this format natively.

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.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 and no data is given then the Loader will take the key and create a filename from that. For example if the key is "alien" and no URL or data is given then the Loader will set the URL to be "alien.json". It will always use .json as the extension.

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 physics json data.

url string <optional>

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

data object | string <optional>

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

format string <optional>
Phaser.Physics.LIME_CORONA_JSON

The format of the physics data.

Source:
src/loader/Loader.js line 1528
Returns:

This Loader instance.

Type
Phaser.Loader

<protected> removeAll()

Remove all file loading requests - this is insufficient to stop current loading. Use reset instead.

Source:
src/loader/Loader.js line 2001

<protected> removeFile(type, key)

Remove a file/asset from the loading queue.

A file that is loaded or has started loading cannot be removed.

Parameters:
Name Type Description
type string

The type of resource to add to the list (image, audio, xml, etc).

key string

Key of the file you want to remove.

Source:
src/loader/Loader.js line 1978

<protected> replaceInFileList(type, key, url, properties)

Internal function that replaces an existing entry in the file list with a new one. Do not call directly.

Parameters:
Name Type Description
type string

The type of resource to add to the list (image, audio, xml, etc).

key string

The unique Cache ID key of this resource.

url string

The URL the asset will be loaded from.

properties object

Any additional properties needed to load the file.

Source:
src/loader/Loader.js line 645

<protected> reset( [hard] [, clearEvents])

Reset the loader and clear any queued assets. If Loader.resetLocked is true this operation will abort.

This will abort any loading and clear any queued assets.

Optionally you can clear any associated events.

Parameters:
Name Type Argument Default Description
hard boolean <optional>
false

If true then the preload sprite and other artifacts may also be cleared.

clearEvents boolean <optional>
false

If true then the all Loader signals will have removeAll called on them.

Source:
src/loader/Loader.js line 515

<protected> resize()

Called automatically by ScaleManager when the game resizes in RESIZE scalemode.

This can be used to adjust the preloading sprite size, eg.

Source:
src/loader/Loader.js line 427

script(key [, url] [, callback] [, callbackContext])

Adds a JavaScript 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.

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.js". It will always add .js as the extension. If you do not desire this action then provide a URL.

Upon successful load the JavaScript is automatically turned into a script tag and executed, so be careful what you load!

A callback, which will be invoked as the script tag has been created, can also be specified. The callback must return relevant data.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the script file.

url string <optional>

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

callback function <optional>
(none)

Optional callback that will be called after the script tag has loaded, so you can perform additional processing.

callbackContext object <optional>
(loader)

The context under which the callback will be applied. If not specified it will use the Phaser Loader as the context.

Source:
src/loader/Loader.js line 1110
Returns:

This Loader instance.

Type
Phaser.Loader

setPreloadSprite(sprite [, direction])

Set a Sprite to be a "preload" sprite by passing it to this method.

A "preload" sprite will have its width or height crop adjusted based on the percentage of the loader in real-time. This allows you to easily make loading bars for games.

The sprite will automatically be made visible when calling this.

Parameters:
Name Type Argument Default Description
sprite Phaser.Sprite | Phaser.Image

The sprite or image that will be cropped during the load.

direction number <optional>
0

A value of zero means the sprite will be cropped horizontally, a value of 1 means its will be cropped vertically.

Source:
src/loader/Loader.js line 393

shader(key [, url] [, overwrite])

Adds a fragment shader 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.getShader(key).

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 "blur" and no URL is given then the Loader will set the URL to be "blur.frag". It will always add .frag 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 fragment file.

url string <optional>

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

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 1058
Returns:

This Loader instance.

Type
Phaser.Loader

spritesheet(key, url, frameWidth, frameHeight [, frameMax] [, margin] [, spacing] [, skipFrames])

Adds a Sprite Sheet 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.

To clarify the terminology that Phaser uses: A Sprite Sheet is an image containing frames, usually of an animation, that are all equal dimensions and often in sequence. For example if the frame size is 32x32 then every frame in the sprite sheet will be that size. Sometimes (outside of Phaser) the term "sprite sheet" is used to refer to a texture atlas. A Texture Atlas works by packing together images as best it can, using whatever frame sizes it likes, often with cropping and trimming the frames in the process. Software such as Texture Packer, Flash CC or Shoebox all generate texture atlases, not sprite sheets. If you've got an atlas then use Loader.atlas instead.

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

Retrieve the file via Cache.getImage(key). Sprite sheets, being image based, live in the same Cache as all other Images.

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.png". It will always add .png as the extension. If you do not desire this action then provide a URL.

An image with four frames, margin = 1, and spacing = 2 looks like this:

........
.#  #  .
.      .
.      .
.#  #  .
.      .
.      .
........

.  margin
   spacing
#  sprite frame

spacing must be on only the right and bottom edges of each frame, including the last row and column.

The first sprite frame is found at (margin) px from the left of the image. The second sprite frame is found at (margin + frameWidth + spacing) px from the left of the image, and so on.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the sheet file.

url string

URL of the sprite sheet 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".

frameWidth number

Width in pixels of a single frame in the sprite sheet.

frameHeight number

Height in pixels of a single frame in the sprite sheet.

frameMax number <optional>
-1

How many frames in this sprite sheet. If not specified it will divide the whole image into frames.

margin number <optional>
0

The distance from the top-left of the image to the top-left of the first frame, if any.

spacing number <optional>
0

The distance from the right edge of a frame to the left edge of the next frame on the same row, from the right edge of the last frame of a row to the margin, from the bottom edge of a frame to the top edge of the next frame on the same column, and from the bottom edge of the last frame of a column to the margin.

skipFrames number <optional>
0

Skip a number of frames. Useful when there are multiple sprite sheets in one image.

Source:
src/loader/Loader.js line 1181
Returns:

This Loader instance.

Type
Phaser.Loader

start()

Start loading the assets. Normally you don't need to call this yourself as the StateManager will do so.

Source:
src/loader/Loader.js line 2013

text(key [, url] [, overwrite])

Adds a Text 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.getText(key)

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.txt". It will always add .txt 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 text file.

url string <optional>

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

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 1005
Returns:

This Loader instance.

Type
Phaser.Loader

texture(key, object [, overwrite])

Adds a Compressed Texture Image to the current load queue.

Compressed Textures are a WebGL only feature, and require 3rd party tools to create. Available tools include Texture Packer, PVRTexTool, DirectX Texture Tool and Mali Texture Compression Tool.

Supported texture compression formats are: PVRTC, S3TC and ETC1. Supported file formats are: PVR, DDS, KTX and PKM.

The formats that support all 3 compression algorithms are PVR and KTX. PKM only supports ETC1, and DDS only S3TC for now.

The texture path object looks like this:

load.texture('factory', {
    etc1: 'assets/factory_etc1.pkm',
    s3tc: 'assets/factory_dxt1.pvr',
    pvrtc: 'assets/factory_pvrtc.pvr',
    truecolor: 'assets/factory.png'
});

The truecolor property points to a standard PNG file, that will be used if none of the compressed formats are supported by the browser / GPU.

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 image via Cache.getImage(key)

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.pvr". It will always add .pvr 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 this image file.

object object

The texture path data object.

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 888
Returns:

This Loader instance.

Type
Phaser.Loader

tilemap(key [, url] [, data] [, format])

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.

Source:
src/loader/Loader.js line 1416
Returns:

This Loader instance.

Type
Phaser.Loader

tilemapCSV(key [, url] [, data])

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

Parameters:
Name Type Argument 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>.csv, i.e. if key was "level1" then the URL will be "level1.csv".

data string <optional>

A CSV data string. If given then the url is ignored and this is used for map data instead.

Source:
src/loader/Loader.js line 1496
See:
Returns:

This Loader instance.

Type
Phaser.Loader

tilemapTiledJSON(key [, url] [, data])

Adds a Tiled JSON Map data file to the current load queue.

Parameters:
Name Type Argument 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>

A JSON data object or string. If given then the url is ignored and this is used for map data instead.

Source:
src/loader/Loader.js line 1512
See:
Returns:

This Loader instance.

Type
Phaser.Loader

<protected> totalLoadedFiles()

Returns the number of files that have already been loaded, even if they errored.

Source:
src/loader/Loader.js line 3291
Returns:

The number of files that have already been loaded (even if they errored)

Type
number

<protected> totalLoadedPacks()

Returns the number of asset packs that have already been loaded, even if they errored.

Source:
src/loader/Loader.js line 3315
Returns:

The number of asset packs that have already been loaded (even if they errored)

Type
number

<protected> totalQueuedFiles()

Returns the number of files still waiting to be processed in the load queue. This value decreases as each file in the queue is loaded.

Source:
src/loader/Loader.js line 3303
Returns:

The number of files that still remain in the load queue.

Type
number

<protected> totalQueuedPacks()

Returns the number of asset packs still waiting to be processed in the load queue. This value decreases as each pack in the queue is loaded.

Source:
src/loader/Loader.js line 3327
Returns:

The number of asset packs that still remain in the load queue.

Type
number

<protected> transformUrl(url, file)

Transforms the asset URL.

The default implementation prepends the baseURL if the url doesn't begin with http or //

Parameters:
Name Type Description
url string

The url to transform.

file object

The file object being transformed.

Source:
src/loader/Loader.js line 2350
Returns:

The transformed url. In rare cases where the url isn't specified it will return false instead.

Type
string

video(key, urls [, loadEvent] [, asBlob])

Adds a video 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.getVideo(key).

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

You don't need to preload a video in order to play it in your game. See Video.createVideoFromURL for details.

Parameters:
Name Type Argument Default Description
key string

Unique asset key of the video file.

urls string | Array.<string> | Array.<object>

Either a single string or an array of URIs or pairs of {uri: .., type: ..}. If an array is specified then the first URI (or URI + mime pair) that is device-compatible will be selected. For example: "boom.mp4", ['boom.mp4', 'boom.ogg', 'boom.webm'], or [{uri: "data:<opus_resource>", type: 'opus'}, 'fallback.mp4']. BLOB and DATA URIs can be used but only support automatic detection when used in the pair form; otherwise the format must be manually checked before adding the resource.

loadEvent string <optional>
'canplaythrough'

This sets the Video source event to listen for before the load is considered complete. 'canplaythrough' implies the video has downloaded enough, and bandwidth is high enough that it can be played to completion. 'canplay' implies the video has downloaded enough to start playing, but not necessarily to finish. 'loadeddata' just makes sure that the video meta data and first frame have downloaded. Phaser uses this value automatically if the browser is detected as being Firefox and no loadEvent is given, otherwise it defaults to canplaythrough.

asBlob boolean <optional>
false

Video files can either be loaded via the creation of a video element which has its src property set. Or they can be loaded via xhr, stored as binary data in memory and then converted to a Blob. This isn't supported in IE9 or Android 2. If you need to have the same video playing at different times across multiple Sprites then you need to load it as a Blob.

Source:
src/loader/Loader.js line 1363
Returns:

This Loader instance.

Type
Phaser.Loader

withSyncPoint(callback [, callbackContext])

Add a synchronization point to the assets / files added within the supplied callback.

A synchronization point denotes that an asset must be completely loaded before subsequent assets can be loaded. An asset marked as a sync-point does not need to wait for previous assets to load (unless they are sync-points). Resources, such as packs, may still be downloaded around sync-points, as long as they do not finalize loading.

Parameters:
Name Type Argument Default Description
callback function

The callback is invoked and is supplied with a single argument: the loader.

callbackContext object <optional>
(loader)

Context for the callback.

Source:
src/loader/Loader.js line 1926
Returns:

This Loader instance.

Type
Phaser.Loader

xml(key [, url] [, overwrite])

Adds an XML 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.getXML(key).

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.xml". It will always add .xml 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 xml file.

url string <optional>

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

overwrite boolean <optional>
false

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

Source:
src/loader/Loader.js line 1084
Returns:

This Loader instance.

Type
Phaser.Loader

phaser-ce@2.20.1 is on GitHub and NPM

Documentation generated by JSDoc 3.6.11 on 2024-10-05 using Tomorrow.