new Cache(game)
Phaser has one single cache in which it stores all assets.
The cache is split up into sections, such as images, sounds, video, json, etc. All assets are stored using a unique string-based key as their identifier. Assets stored in different areas of the cache can have the same key, for example 'playerWalking' could be used as the key for both a sprite sheet and an audio file, because they are unique data types.
The cache is automatically populated by the Phaser.Loader. When you use the loader to pull in external assets such as images they are automatically placed into their respective cache. Most common Game Objects, such as Sprites and Videos automatically query the cache to extract the assets they need on instantiation.
You can access the cache from within a State via this.cache
. From here you can call any public method it has,
including adding new entries to it, deleting them or querying them.
Understand that almost without exception when you get an item from the cache it will return a reference to the item stored in the cache, not a copy of it. Therefore if you retrieve an item and then modify it, the original object in the cache will also be updated, even if you don't put it back into the cache again.
By default when you change State the cache is not cleared, although there is an option to clear it should your game require it. In a typical game set-up the cache is populated once after the main game has loaded and then used as an asset store.
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
- Source:
- src/loader/Cache.js line 34
Members
-
<static, constant> BINARY : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 180
-
<static, constant> BITMAPDATA : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 186
-
<static, constant> BITMAPFONT : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 192
-
<static, constant> CANVAS : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 138
-
<static, constant> DATA : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 228
-
<static, constant> DEFAULT : PIXI.Texture
-
The default image used for a texture when no other is specified.
Type:
- Source:
- src/loader/Cache.js line 235
-
<static, constant> DEFAULT_KEY : string
-
Key for the DEFAULT texture.
Type:
- string
- Source:
- src/loader/Cache.js line 242
-
<static, constant> DEFAULT_SRC : string
-
URL for the DEFAULT texture.
Type:
- string
- Source:
- src/loader/Cache.js line 249
-
<static, constant> IMAGE : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 144
-
<static, constant> JSON : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 198
-
<static, constant> MISSING : PIXI.Texture
-
The default image used for a texture when the source image is missing.
Type:
- Source:
- src/loader/Cache.js line 256
-
<static, constant> MISSING_KEY : string
-
Key for the MISSING texture.
Type:
- string
- Source:
- src/loader/Cache.js line 263
-
<static, constant> MISSING_SRC : string
-
URL for the MISSING texture.
Type:
- string
- Source:
- src/loader/Cache.js line 270
-
<static, constant> PHYSICS : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 168
-
<static> READY_TIMEOUT : number
-
The maximum amount of time (ms) to wait for the built-in DEFAULT and MISSING images to load.
Type:
- number
- Default Value:
-
- 1000
- Source:
- src/loader/Cache.js line 278
-
<static, constant> RENDER_TEXTURE : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 222
-
<static, constant> SHADER : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 216
-
<static, constant> SOUND : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 156
-
<static, constant> TEXT : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 162
-
<static, constant> TEXTURE : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 150
-
<static, constant> TILEMAP : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 174
-
<static, constant> VIDEO : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 210
-
<static, constant> XML : number
-
Type:
- number
- Source:
- src/loader/Cache.js line 204
-
autoResolveURL : boolean
-
Automatically resolve resource URLs to absolute paths for use with the Cache.getURL method.
Type:
- boolean
- Source:
- src/loader/Cache.js line 45
-
game : Phaser.Game
-
Local reference to game.
Type:
- Source:
- src/loader/Cache.js line 39
-
onReady : Phaser.Signal
-
Dispatched when the DEFAULT and MISSING images have loaded (or the load timeout was exceeded).
Type:
- Source:
- src/loader/Cache.js line 129
-
onSoundUnlock : Phaser.Signal
-
This event is dispatched when the sound system is unlocked via a touch event on cellular devices.
Type:
- Source:
- src/loader/Cache.js line 93
Methods
-
addBinary(key, binaryData)
-
Add a binary object in to the cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
binaryData
object The binary object to be added to the cache.
- Source:
- src/loader/Cache.js line 534
-
addBitmapData(key, bitmapData [, frameData])
-
Add a BitmapData object to the cache.
Parameters:
Name Type Argument Default Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
bitmapData
Phaser.BitmapData The BitmapData object to be addded to the cache.
frameData
Phaser.FrameData | null <optional>
(auto create) Optional FrameData set associated with the given BitmapData. If not specified (or
undefined
) a new FrameData object is created containing the Bitmap's Frame. Ifnull
is supplied then no FrameData will be created.- Source:
- src/loader/Cache.js line 546
Returns:
The BitmapData object to be addded to the cache.
- Type
- Phaser.BitmapData
-
addBitmapFont(key, url, data, atlasData [, atlasType] [, xSpacing] [, ySpacing])
-
Add a new Bitmap Font to the Cache.
Parameters:
Name Type Argument Default Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra font data.
atlasData
object The Bitmap Font data.
atlasType
string <optional>
'xml' The format of the Bitmap Font data file:
json
orxml
.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/Cache.js line 570
-
addBitmapFontFromAtlas(key, atlasKey, atlasFrame, dataKey [, dataType] [, xSpacing] [, ySpacing])
-
Add a new Bitmap Font to the Cache, where the font texture is part of a Texture Atlas.
The atlas must already exist in the cache, and be available based on the given
atlasKey
.The
atlasFrame
specifies the name of the frame within the atlas that the Bitmap Font is stored in.The
dataKey
is the key of the XML or JSON Bitmap Font Data, which must already be in the Cache.Parameters:
Name Type Argument Default Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
atlasKey
string The key of the Texture Atlas in the Cache.
atlasFrame
string The frame of the Texture Atlas that the Bitmap Font is in.
dataKey
string The key of the Bitmap Font data in the Cache
dataType
string <optional>
'xml' The format of the Bitmap Font data:
json
orxml
.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/Cache.js line 608
-
addCanvas(key, canvas [, context])
-
Add a new canvas object in to the cache.
Parameters:
Name Type Argument Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
canvas
HTMLCanvasElement The Canvas DOM element.
context
CanvasRenderingContext2D <optional>
The context of the canvas element. If not specified it will default go
getContext('2d')
.- Source:
- src/loader/Cache.js line 327
-
addData(key, data)
-
Add a data item to the cache.
Parameters:
Name Type Description key
string The key of the data item.
data
any The data.
- Source:
- src/loader/Cache.js line 817
-
<protected> addDefaultImage()
-
Adds a default image to be used in special cases such as WebGL Filters. It uses the special reserved key of
__default
. This method is called automatically when the Cache is created. This image is skipped whenCache.destroy
is called due to its internal requirements.- Source:
- src/loader/Cache.js line 413
-
addImage(key, url, data)
-
Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM. If an image already exists in the cache with the same key then it is removed and destroyed, and the new image inserted in its place.
If the image has not yet been fetched (successfully or not), a
console.warn
message will be displayed.Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra image data.
- Source:
- src/loader/Cache.js line 342
Returns:
The full image object that was added to the cache.
- Type
- object
-
addJSON(key, url, data)
-
Add a new json object into the cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra json data.
- Source:
- src/loader/Cache.js line 662
-
<protected> addMissingImage()
-
Adds an image to be used when a key is wrong / missing. It uses the special reserved key of
__missing
. This method is called automatically when the Cache is created. This image is skipped whenCache.destroy
is called due to its internal requirements.- Source:
- src/loader/Cache.js line 434
-
addPhysicsData(key, url, JSONData, format)
-
Add a new physics data object to the Cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.JSONData
object The physics data object (a JSON file).
format
number The format of the physics data.
- Source:
- src/loader/Cache.js line 502
-
addRenderTexture(key, texture)
-
Add a new Phaser.RenderTexture in to the cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
texture
Phaser.RenderTexture The texture to use as the base of the RenderTexture.
- Source:
- src/loader/Cache.js line 723
-
addShader(key, url, data)
-
Adds a Fragment Shader in to the Cache. The file must have already been loaded, typically via Phaser.Loader.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra shader data.
- Source:
- src/loader/Cache.js line 708
-
addSound(key, url, data, webAudio, audioTag)
-
Adds a Sound file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra sound data.
webAudio
boolean True if the file is using web audio.
audioTag
boolean True if the file is using legacy HTML audio.
- Source:
- src/loader/Cache.js line 452
-
addSpriteSheet(key, url, data, frameWidth, frameHeight [, frameMax] [, margin] [, spacing] [, skipFrames])
-
Add a new sprite sheet in to the cache.
Parameters:
Name Type Argument Default Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra sprite sheet data.
frameWidth
number Width of the sprite sheet.
frameHeight
number Height of the sprite sheet.
frameMax
number <optional>
-1 How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly.
margin
number <optional>
0 If the frames have been drawn with a margin, specify the amount here.
spacing
number <optional>
0 If the frames have been drawn with spacing between them, specify the amount here.
skipFrames
number <optional>
0 Skip a number of frames. Useful when there are multiple sprite sheets in one image.
- Source:
- src/loader/Cache.js line 735
-
addText(key, url, data)
-
Add a new text data.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra text data.
- Source:
- src/loader/Cache.js line 487
-
addTextureAtlas(key, url, data, atlasData, format)
-
Add a new texture atlas to the Cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra texture atlas data.
atlasData
object Texture atlas frames data.
format
number The format of the texture atlas.
- Source:
- src/loader/Cache.js line 772
-
addTilemap(key, url, mapData, format)
-
Add a new tilemap to the Cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.mapData
object The tilemap data object (either a CSV or JSON file).
format
number The format of the tilemap data.
- Source:
- src/loader/Cache.js line 518
-
addVideo(key, url, data, isBlob)
-
Adds a Video file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra video data.
isBlob
boolean True if the file was preloaded via xhr and the data parameter is a Blob. false if a Video tag was created instead.
- Source:
- src/loader/Cache.js line 692
-
addXML(key, url, data)
-
Add a new xml object into the cache.
Parameters:
Name Type Description key
string The key that this asset will be stored in the cache under. This should be unique within this cache.
url
string The URL the asset was loaded from. If the asset was not loaded externally set to
null
.data
object Extra text data.
- Source:
- src/loader/Cache.js line 677
-
checkBinaryKey(key)
-
Checks if the given key exists in the Binary Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1084
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkBitmapDataKey(key)
-
Checks if the given key exists in the BitmapData Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1096
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkBitmapFontKey(key)
-
Checks if the given key exists in the BitmapFont Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1108
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkCanvasKey(key)
-
Checks if the given key exists in the Canvas Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 988
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkDataKey(key)
-
Checks if the given key exists in the Data Cache.
Parameters:
Name Type Description key
string The key of the data item.
- Source:
- src/loader/Cache.js line 1000
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkImageKey(key)
-
Checks if the given key exists in the Image Cache. Note that this also includes Texture Atlases, Sprite Sheets and Retro Fonts.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1012
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkJSONKey(key)
-
Checks if the given key exists in the JSON Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1120
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkKey(cache, key)
-
Checks if a key for the given cache object type exists.
Parameters:
Name Type Description cache
integer The cache to search. One of the Cache consts such as
Phaser.Cache.IMAGE
orPhaser.Cache.SOUND
.key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 950
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkPhysicsKey(key)
-
Checks if the given key exists in the Physics Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1060
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkRenderTextureKey(key)
-
Checks if the given key exists in the Render Texture Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1168
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkShaderKey(key)
-
Checks if the given key exists in the Fragment Shader Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1156
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkSoundKey(key)
-
Checks if the given key exists in the Sound Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1036
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkTextKey(key)
-
Checks if the given key exists in the Text Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1048
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkTextureKey(key)
-
Checks if the given key exists in the Texture Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1024
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkTilemapKey(key)
-
Checks if the given key exists in the Tilemap Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1072
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkURL(url)
-
Checks if the given URL has been loaded into the Cache. This method will only work if Cache.autoResolveURL was set to
true
before any preloading took place. The method will make a DOM src call to the URL given, so please be aware of this for certain file types, such as Sound files on Firefox which may cause double-load instances.Parameters:
Name Type Description url
string The url to check for in the cache.
- Source:
- src/loader/Cache.js line 968
Returns:
True if the url exists, otherwise false.
- Type
- boolean
-
checkVideoKey(key)
-
Checks if the given key exists in the Video Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1144
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
checkXMLKey(key)
-
Checks if the given key exists in the XML Cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 1132
Returns:
True if the key exists in the cache, otherwise false.
- Type
- boolean
-
<protected> clearGLTextures()
-
Empties out all of the GL Textures from Images stored in the cache. This is called automatically when the WebGL context is lost and then restored.
- Source:
- src/loader/Cache.js line 2034
-
decodedSound(key, data)
-
Add a new decoded sound.
Parameters:
Name Type Description key
string The key of the asset within the cache.
data
object Extra sound data.
- Source:
- src/loader/Cache.js line 893
-
destroy()
-
Clears the cache. Removes every local cache object reference. If an object in the cache has a
destroy
method it will be called; otherwise,destroy
will be called on any of the object'sbase
,data
,frameData
, ortexture
properties.- Source:
- src/loader/Cache.js line 2082
-
<protected> destroyItem(item)
-
Parameters:
Name Type Description item
object - Source:
- src/loader/Cache.js line 2112
-
getBaseTexture(key [, cache])
-
Gets a PIXI.BaseTexture by key from the given Cache.
Parameters:
Name Type Argument Default Description key
string Asset key of the image for which you want the BaseTexture for.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search for the item in.
- Source:
- src/loader/Cache.js line 1582
Returns:
The BaseTexture object.
- Type
- PIXI.BaseTexture
-
getBinary(key)
-
Gets a binary object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1416
Returns:
The binary data object.
- Type
- object
-
getBitmapData(key)
-
Gets a BitmapData object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1432
Returns:
The requested BitmapData object if found, or null if not.
- Type
- Phaser.BitmapData
-
getBitmapFont(key)
-
Gets a Bitmap Font object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1448
Returns:
The requested BitmapFont object if found, or null if not.
- Type
- Phaser.BitmapFont
-
getCanvas(key)
-
Gets a Canvas object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1221
Returns:
The canvas object or
null
if no item could be found matching the given key.- Type
- object
-
getData(key)
-
Gets an item from the data cache.
Parameters:
Name Type Description key
string The key of the data item.
- Source:
- src/loader/Cache.js line 1564
Returns:
The data.
- Type
- any
-
getFrame(key [, cache])
-
Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
Parameters:
Name Type Argument Default Description key
string Asset key of the frame data to retrieve from the Cache.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search for the item in.
- Source:
- src/loader/Cache.js line 1597
Returns:
The frame data.
- Type
- Phaser.Frame
-
getFrameByIndex(key, index [, cache])
-
Get a single frame out of a frameData set by key.
Parameters:
Name Type Argument Default Description key
string Asset key of the frame data to retrieve from the Cache.
index
number The index of the frame you want to get.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search. One of the Cache consts such as
Phaser.Cache.IMAGE
orPhaser.Cache.SOUND
.- Source:
- src/loader/Cache.js line 1686
Returns:
The frame object.
- Type
- Phaser.Frame
-
getFrameByName(key, name [, cache])
-
Get a single frame out of a frameData set by key.
Parameters:
Name Type Argument Default Description key
string Asset key of the frame data to retrieve from the Cache.
name
string The name of the frame you want to get.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search. One of the Cache consts such as
Phaser.Cache.IMAGE
orPhaser.Cache.SOUND
.- Source:
- src/loader/Cache.js line 1709
Returns:
The frame object.
- Type
- Phaser.Frame
-
getFrameCount(key [, cache])
-
Get the total number of frames contained in the FrameData object specified by the given key.
Parameters:
Name Type Argument Default Description key
string Asset key of the FrameData you want.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search for the item in.
- Source:
- src/loader/Cache.js line 1612
Returns:
Then number of frames. 0 if the image is not found.
- Type
- number
-
getFrameData(key [, cache])
-
Gets a Phaser.FrameData object from the Image Cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Argument Default Description key
string Asset key of the frame data to retrieve from the Cache.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search for the item in.
- Source:
- src/loader/Cache.js line 1634
Returns:
The frame data.
- Type
- Phaser.FrameData
-
getImage( [key] [, full])
-
Gets a Image object from the cache. This returns a DOM Image object, not a Phaser.Image object.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Only the Image cache is searched, which covers images loaded via Loader.image, Sprite Sheets and Texture Atlases.
If you need the image used by a bitmap font or similar then please use those respective 'get' methods.
Parameters:
Name Type Argument Default Description key
string <optional>
The key of the asset to retrieve from the cache. If not given or null it will return a default image. If given but not found in the cache it will throw a warning and return the missing image.
full
boolean <optional>
false If true the full image object will be returned, if false just the HTML Image object is returned.
- Source:
- src/loader/Cache.js line 1237
Returns:
The Image object if found in the Cache, otherwise
null
. Iffull
was true then a JavaScript object is returned.- Type
- Image
-
getItem(key, cache [, method] [, property])
-
Get an item from a cache based on the given key and property.
This method is mostly used internally by other Cache methods such as
getImage
but is exposed publicly for your own use as well.Parameters:
Name Type Argument Description key
string The key of the asset within the cache.
cache
integer The cache to search. One of the Cache consts such as
Phaser.Cache.IMAGE
orPhaser.Cache.SOUND
.method
string <optional>
The string name of the method calling getItem. Can be empty, in which case no console warning is output.
property
string <optional>
If you require a specific property from the cache item, specify it here.
- Source:
- src/loader/Cache.js line 1186
Returns:
The cached item if found, otherwise
null
. If the key is invalid andmethod
is set then a console.warn is output.- Type
- object
-
getJSON(key [, clone])
-
Gets a JSON object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.You can either return the object by reference (the default), or return a clone of it by setting the
clone
argument totrue
.Parameters:
Name Type Argument Default Description key
string The key of the asset to retrieve from the cache.
clone
boolean <optional>
false Return a clone of the original object (true) or a reference to it? (false)
- Source:
- src/loader/Cache.js line 1464
Returns:
The JSON object, or an Array if the key points to an Array property. If the property wasn't found, it returns null.
- Type
- object
-
getKeys( [cache])
-
Gets all keys used in the requested Cache.
Parameters:
Name Type Argument Default Description cache
integer <optional>
Phaser.Cache.IMAGE The Cache you wish to get the keys from. Can be any of the Cache consts such as
Phaser.Cache.IMAGE
,Phaser.Cache.SOUND
etc.- Source:
- src/loader/Cache.js line 1756
Returns:
The array of keys in the requested cache.
- Type
- Array
-
getPhysicsData(key [, object], fixtureKey)
-
Gets a Physics Data object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.You can get either the entire data set, a single object or a single fixture of an object from it.
Parameters:
Name Type Argument Default Description key
string The key of the asset to retrieve from the cache.
object
string <optional>
null If specified it will return just the physics object that is part of the given key, if null it will return them all.
fixtureKey
string Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
- Source:
- src/loader/Cache.js line 1341
Returns:
The requested physics object data if found.
- Type
- object
-
getRenderTexture(key)
-
Gets a RenderTexture object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1548
Returns:
The object with Phaser.RenderTexture and Phaser.Frame.
- Type
- Object
-
getShader(key)
-
Gets a fragment shader object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1532
Returns:
The shader object.
- Type
- string
-
getSound(key)
-
Gets a Phaser.Sound object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1293
Returns:
The sound object.
- Type
- Phaser.Sound
-
getSoundData(key)
-
Gets a raw Sound data object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1309
Returns:
The sound data.
- Type
- object
-
getText(key)
-
Gets a Text object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1325
Returns:
The text data.
- Type
- object
-
getTextureFrame(key)
-
Get a single texture frame by key.
You'd only do this to get the default Frame created for a non-atlas / spritesheet image.
Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1279
Returns:
The frame data.
- Type
- Phaser.Frame
-
getTilemapData(key)
-
Gets a raw Tilemap data object from the cache. This will be in either CSV or JSON format.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1400
Returns:
The raw tilemap data in CSV or JSON format.
- Type
- object
-
getURL(url)
-
Get a cached object by the URL. This only returns a value if you set Cache.autoResolveURL to
true
before starting the preload of any assets. Be aware that every call to this function makes a DOM src query, so use carefully and double-check for implications in your target browsers/devices.Parameters:
Name Type Description url
string The url for the object loaded to get from the cache.
- Source:
- src/loader/Cache.js line 1732
Returns:
The cached object.
- Type
- object
-
getVideo(key)
-
Gets a Phaser.Video object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1516
Returns:
The video object.
- Type
- Phaser.Video
-
getXML(key)
-
Gets an XML object from the cache.
The object is looked-up based on the key given.
Note: If the object cannot be found a
console.warn
message is displayed.Parameters:
Name Type Description key
string The key of the asset to retrieve from the cache.
- Source:
- src/loader/Cache.js line 1500
Returns:
The XML object.
- Type
- object
-
hasFrameData(key [, cache])
-
Check if the FrameData for the given key exists in the Image Cache.
Parameters:
Name Type Argument Default Description key
string Asset key of the frame data to retrieve from the Cache.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search for the item in.
- Source:
- src/loader/Cache.js line 1653
Returns:
True if the given key has frameData in the cache, otherwise false.
- Type
- boolean
-
isSoundDecoded(key)
-
Check if the given sound has finished decoding.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 909
Returns:
The decoded state of the Sound object.
- Type
- boolean
-
isSoundReady(key)
-
Check if the given sound is ready for playback. A sound is considered ready when it has finished decoding and the device is no longer touch locked.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 926
Returns:
True if the sound is decoded and the device is not touch locked.
- Type
- boolean
-
reloadSound(key)
-
Reload a Sound file from the server.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 835
-
reloadSoundComplete(key)
-
Fires the onSoundUnlock event when the sound has completed reloading.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 860
-
removeBinary(key)
-
Removes a binary file from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1889
-
removeBitmapData(key)
-
Removes a bitmap data from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1903
-
removeBitmapFont(key)
-
Removes a bitmap font from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1917
-
removeCanvas(key)
-
Removes a canvas from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1789
-
removeImage(key [, destroyBaseTexture])
-
Removes an image from the cache.
You can optionally elect to destroy it as well. This calls BaseTexture.destroy on it.
Note that this only removes it from the Phaser Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Argument Default Description key
string Key of the asset you want to remove.
destroyBaseTexture
boolean <optional>
true Should the BaseTexture behind this image also be destroyed?
- Source:
- src/loader/Cache.js line 1803
-
removeJSON(key)
-
Removes a json object from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1931
-
removePhysics(key)
-
Removes a physics data file from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1861
-
removeRenderTexture(key)
-
Removes a Render Texture from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1987
-
removeShader(key)
-
Removes a shader from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1973
-
removeSound(key)
-
Removes a sound from the cache.
If any
Phaser.Sound
objects use the audio file in the cache that you remove with this method, they will automatically destroy themselves. If you wish to have full control over when Sounds are destroyed then you must finish your house-keeping and destroy them all yourself first, before calling this method.Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1829
-
removeSpriteSheet(key)
-
Removes a Sprite Sheet from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 2001
-
removeText(key)
-
Removes a text file from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1847
-
removeTextureAtlas(key)
-
Removes a Texture Atlas from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 2015
-
removeTilemap(key)
-
Removes a tilemap from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1875
-
removeVideo(key)
-
Removes a video from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1959
-
removeXML(key)
-
Removes a xml object from the cache.
Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere then it will persist in memory.
Parameters:
Name Type Description key
string Key of the asset you want to remove.
- Source:
- src/loader/Cache.js line 1945
-
updateFrameData(key, frameData [, cache])
-
Replaces a set of frameData with a new Phaser.FrameData object.
Parameters:
Name Type Argument Default Description key
string The unique key by which you will reference this object.
frameData
number The new FrameData.
cache
integer <optional>
Phaser.Cache.IMAGE The cache to search. One of the Cache consts such as
Phaser.Cache.IMAGE
orPhaser.Cache.SOUND
.- Source:
- src/loader/Cache.js line 1668
-
updateSound(key)
-
Updates the sound object in the cache.
Parameters:
Name Type Description key
string The key of the asset within the cache.
- Source:
- src/loader/Cache.js line 877