Phaser.Loader.File
createObjectURL
<static> createObjectURL(image, blob, defaultType)
Description:
Static method for creating an object URL using the URL API and setting it as the image 'src' attribute. If the URL API is not supported (usually on old browsers) it falls back to creating a Base64 encoded URL using FileReader.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| image | HTMLImageElement | No | Image object which 'src' attribute should be set to object URL. |
| blob | Blob | No | A Blob object to create an object URL for. |
| defaultType | string | No | Default mime type used if blob type is not available. |
Source: src/loader/File.js#L571
Since: 3.7.0
revokeObjectURL
<static> revokeObjectURL(image)
Description:
Static method for releasing an existing object URL which was previously created by calling Phaser.Loader.File.createObjectURL method.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| image | HTMLImageElement | No | Image object which 'src' attribute should be revoked. |
Source: src/loader/File.js#L605
Since: 3.7.0
Phaser.Loader.FileTypesManager
install
<static> install(loader)
Description:
Static method called when a LoaderPlugin is created.
Loops through the local types object and injects all of them as properties into the LoaderPlugin instance.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| loader | Phaser.Loader.LoaderPlugin | No | The LoaderPlugin to install the types into. |
Source: src/loader/FileTypesManager.js#L22
Since: 3.0.0
register
<static> register(key, factoryFunction)
Description:
Static method called directly by the File Types.
The key is a reference to the function used to load the files via the Loader, i.e. image.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| key | string | No | The key that will be used as the method name in the LoaderPlugin. |
| factoryFunction | function | No | The function that will be called when LoaderPlugin.key is invoked. |
Source: src/loader/FileTypesManager.js#L41
Since: 3.0.0
destroy
<static> destroy()
Description:
Removes all associated file types.
Source: src/loader/FileTypesManager.js#L57
Since: 3.0.0
GetURL
<static> GetURL(file, baseURL)
Description:
Given a File and a baseURL value, this returns the URL the File will use to download from.
If the file has no URL, false is returned. If the file URL is already absolute (i.e. it begins with blob:, data:, capacitor://, file://, http://, https://, or //), it is returned as-is. Otherwise, the baseURL is prepended to the file URL to form a complete URL.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| file | Phaser.Loader.File | No | The File object whose URL will be resolved. |
| baseURL | string | No | A default base URL to prepend when the file URL is relative. |
Returns: string - The resolved URL the File will use to download from, or false if the file has no URL.
Source: src/loader/GetURL.js#L7
Since: 3.0.0
MergeXHRSettings
<static> MergeXHRSettings(global, local)
Description:
Takes two XHRSettings Objects and creates a new XHRSettings object from them.
The new object is seeded by the values given in the global settings, but any setting in the local object overrides the global ones.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| global | Phaser.Types.Loader.XHRSettingsObject | No | The global XHRSettings object. |
| local | Phaser.Types.Loader.XHRSettingsObject | No | The local XHRSettings object. |
Returns: Phaser.Types.Loader.XHRSettingsObject - A newly formed XHRSettings object.
Source: src/loader/MergeXHRSettings.js#L10
Since: 3.0.0
XHRLoader
<static> XHRLoader(file, globalXHRSettings)
Description:
Creates a new XMLHttpRequest (xhr) object based on the given File and XHRSettings and starts the download of it. It uses the File's own XHRSettings and merges them with the global XHRSettings object to set the xhr values before download.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| file | Phaser.Loader.File | No | The File to download. |
| globalXHRSettings | Phaser.Types.Loader.XHRSettingsObject | No | The global XHRSettings object. |
Returns: XMLHttpRequest - The XHR object. For base64 files, file.onBase64Load is called directly and this function returns undefined.
Source: src/loader/XHRLoader.js#L9
Since: 3.0.0
XHRSettings
<static> XHRSettings([responseType], [async], [user], [password], [timeout], [withCredentials])
Description:
Creates an XHRSettings Object with default values.
The XHRSettings object is used by the Phaser Loader when making XMLHttpRequest calls to fetch external assets such as images, audio, JSON, and other files. You can pass a custom XHRSettings object to individual file load calls (e.g., this.load.image) to override the default request configuration on a per-file basis, or set global defaults via the Loader's xhr property. This is useful when loading from servers that require authentication credentials, custom headers, a specific MIME type override, or a non-default response type.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| responseType | XMLHttpRequestResponseType | Yes | "''" | The responseType, such as 'text'. |
| async | boolean | Yes | true | Should the XHR request use async or not? |
| user | string | Yes | "''" | Optional username for the XHR request. |
| password | string | Yes | "''" | Optional password for the XHR request. |
| timeout | number | Yes | 0 | Optional XHR timeout value, in milliseconds. A value of 0 disables the timeout. |
| withCredentials | boolean | Yes | false | Optional XHR withCredentials value. |
Returns: Phaser.Types.Loader.XHRSettingsObject - The XHRSettings object as used by the Loader.
Source: src/loader/XHRSettings.js#L7
Since: 3.0.0
Phaser.Loader.FileTypes.AudioFile
create
<static> create(loader, key, [urls], [config], [xhrSettings])
Description:
Static factory method that creates the correct type of audio file for the current device.
Inspects the game's audio configuration and device capabilities to decide whether to return a Web Audio API-based AudioFile or a fallback HTML5AudioFile. It first calls AudioFile.getAudioURL to find a suitable URL from the provided list that the browser can play. If no compatible URL is found, a warning is logged and null is returned.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| loader | Phaser.Loader.LoaderPlugin | No | A reference to the Loader that is responsible for this file. |
| key | string | Phaser.Types.Loader.FileTypes.AudioFileConfig | No | The key to use for this file, or a file configuration object. |
| urls | string | Array.<string> | Phaser.Types.Loader.FileTypes.AudioFileURLConfig | Array.<Phaser.Types.Loader.FileTypes.AudioFileURLConfig> |
| config | any | Yes | An object containing an instances property for HTML5Audio. Defaults to 1. |
| xhrSettings | Phaser.Types.Loader.XHRSettingsObject | Yes | Extra XHR Settings specifically for this file. |
Returns: Phaser.Loader.FileTypes.AudioFile, Phaser.Loader.FileTypes.HTML5AudioFile - The created audio file instance, or null if no supported URL was found.
Source: src/loader/filetypes/AudioFile.js#L115
Since: 3.0.0
getAudioURL
<static> getAudioURL(game, urls)
Description:
Takes an array of audio URLs and returns a URL config object for the first entry that the current device is capable of playing, based on the audio format indicated by the file extension or an explicit type property on the URL config object.
Blob and data URIs are always accepted and returned immediately regardless of format. For regular URLs, the extension is extracted from the filename and checked against game.device.audio. If no supported URL is found, null is returned.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| game | Phaser.Game | No | A reference to the Phaser Game instance. |
| urls | string | Array.<string> | Phaser.Types.Loader.FileTypes.AudioFileURLConfig | Array.<Phaser.Types.Loader.FileTypes.AudioFileURLConfig> |
Returns: Phaser.Types.Loader.FileTypes.AudioFileURLConfig - A URL config object with url and type properties for the first supported audio URL, or null if none are supported.
Source: src/loader/filetypes/AudioFile.js#L169
Since: 3.0.0