new Cache(game)
A game only has one instance of a Cache and it is used to store all externally loaded assets such as images, sounds and data files as a result of Loader calls. Cached items use string based keys for look-up.
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
- Source:
Members
-
<static, constant> BINARY :number
-
Type:
- number
- Source:
-
<static, constant> BITMAPDATA :number
-
Type:
- number
- Source:
-
<static, constant> BITMAPFONT :number
-
Type:
- number
- Source:
-
<static, constant> CANVAS :number
-
Type:
- number
- Source:
-
<static, constant> IMAGE :number
-
Type:
- number
- Source:
-
<static, constant> JSON :number
-
Type:
- number
- Source:
-
<static, constant> PHYSICS :number
-
Type:
- number
- Source:
-
<static, constant> SOUND :number
-
Type:
- number
- Source:
-
<static, constant> TEXT :number
-
Type:
- number
- Source:
-
<static, constant> TEXTURE :number
-
Type:
- number
- Source:
-
<static, constant> TILEMAP :number
-
Type:
- number
- Source:
-
<static, constant> XML :number
-
Type:
- number
- Source:
-
_cacheMap
-
- Source:
Properties:
Name Type Description _cacheMaparray Const to cache object look-up array.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game Local reference to game.
-
onSoundUnlock
-
- Source:
Properties:
Name Type Description onSoundUnlockPhaser.Signal This event is dispatched when the sound system is unlocked via a touch event on cellular devices.
Methods
-
addBinary(key, binaryData)
-
Add a binary object in to the cache.
Parameters:
Name Type Description keystring Asset key for this binary data.
binaryDataobject The binary object to be addded to the cache.
- Source:
-
addBitmapData(key, bitmapData, frameData) → {Phaser.BitmapData}
-
Add a BitmapData object in to the cache.
Parameters:
Name Type Argument Description keystring Asset key for this BitmapData.
bitmapDataPhaser.BitmapData The BitmapData object to be addded to the cache.
frameDataPhaser.FrameData <optional>
Optional FrameData set associated with the given BitmapData.
- Source:
Returns:
The BitmapData object to be addded to the cache.
- Type
- Phaser.BitmapData
-
addBitmapFont(key, url, data, xmlData, xSpacing, ySpacing)
-
Add a new Bitmap Font to the Cache.
Parameters:
Name Type Argument Default Description keystring The unique key by which you will reference this object.
urlstring URL of this font xml file.
dataobject Extra font data.
xmlDataobject Texture atlas frames data.
xSpacingnumber <optional>
0 If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
ySpacingnumber <optional>
0 If you'd like to add additional vertical spacing between the lines then set the pixel value here.
- Source:
-
addCanvas(key, canvas, context)
-
Add a new canvas object in to the cache.
Parameters:
Name Type Description keystring Asset key for this canvas.
canvasHTMLCanvasElement Canvas DOM element.
contextCanvasRenderingContext2D Render context of this canvas.
- Source:
-
<protected> addDefaultImage()
-
Adds a default image to be used in special cases such as WebGL Filters. Is mapped to the key __default.
- Source:
-
addImage(key, url, data)
-
Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
urlstring URL of this image file.
dataobject Extra image data.
- Source:
-
addJSON(key, url, data)
-
Add a new json object into the cache.
Parameters:
Name Type Description keystring Asset key for the json data.
urlstring URL of this json data file.
dataobject Extra json data.
- Source:
-
<protected> addMissingImage()
-
Adds an image to be used when a key is wrong / missing. Is mapped to the key __missing.
- Source:
-
addRenderTexture(key, texture)
-
Add a new Phaser.RenderTexture in to the cache.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
texturePhaser.RenderTexture The texture to use as the base of the RenderTexture.
- Source:
-
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 keystring Asset key for the sound.
urlstring URL of this sound file.
dataobject Extra sound data.
webAudioboolean True if the file is using web audio.
audioTagboolean True if the file is using legacy HTML audio.
- Source:
-
addSpriteSheet(key, url, data, frameWidth, frameHeight, frameMax, margin, spacing)
-
Add a new sprite sheet in to the cache.
Parameters:
Name Type Argument Default Description keystring The unique key by which you will reference this object.
urlstring URL of this sprite sheet file.
dataobject Extra sprite sheet data.
frameWidthnumber Width of the sprite sheet.
frameHeightnumber Height of the sprite sheet.
frameMaxnumber <optional>
-1 How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly.
marginnumber <optional>
0 If the frames have been drawn with a margin, specify the amount here.
spacingnumber <optional>
0 If the frames have been drawn with spacing between them, specify the amount here.
- Source:
-
addText(key, url, data)
-
Add a new text data.
Parameters:
Name Type Description keystring Asset key for the text data.
urlstring URL of this text data file.
dataobject Extra text data.
- Source:
-
addTextureAtlas(key, url, data, atlasData, format)
-
Add a new texture atlas to the Cache.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
urlstring URL of this texture atlas file.
dataobject Extra texture atlas data.
atlasDataobject Texture atlas frames data.
formatnumber The format of the texture atlas.
- Source:
-
addTilemap(key, url, mapData, format)
-
Add a new tilemap to the Cache.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
urlstring URL of the tilemap image.
mapDataobject The tilemap data object (either a CSV or JSON file).
formatnumber The format of the tilemap data.
- Source:
-
addTilemap(key, url, JSONData, format)
-
Add a new physics data object to the Cache.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
urlstring URL of the physics json data.
JSONDataobject The physics data object (a JSON file).
formatnumber The format of the physics data.
- Source:
-
addXML(key, url, data)
-
Add a new xml object into the cache.
Parameters:
Name Type Description keystring Asset key for the xml file.
urlstring URL of this xml file.
dataobject Extra text data.
- Source:
-
checkBinaryKey(key) → {boolean}
-
Checks if the given key exists in the Binary Cache.
Parameters:
Name Type Description keystring Asset key of the binary file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkBitmapDataKey(key) → {boolean}
-
Checks if the given key exists in the BitmapData Cache.
Parameters:
Name Type Description keystring Asset key of the BitmapData to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkBitmapFontKey(key) → {boolean}
-
Checks if the given key exists in the BitmapFont Cache.
Parameters:
Name Type Description keystring Asset key of the BitmapFont to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkCanvasKey(key) → {boolean}
-
Checks if the given key exists in the Canvas Cache.
Parameters:
Name Type Description keystring Asset key of the canvas to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkImageKey(key) → {boolean}
-
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 keystring Asset key of the image to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkJSONKey(key) → {boolean}
-
Checks if the given key exists in the JSON Cache.
Parameters:
Name Type Description keystring Asset key of the JSON file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkKey(type, key) → {boolean}
-
Checks if a key for the given cache object type exists.
Parameters:
Name Type Description typenumber The Cache type to check against. I.e. Phaser.Cache.CANVAS, Phaser.Cache.IMAGE, Phaser.Cache.JSON, etc.
keystring Asset key of the image to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkPhysicsKey(key) → {boolean}
-
Checks if the given key exists in the Physics Cache.
Parameters:
Name Type Description keystring Asset key of the physics data file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkSoundKey(key) → {boolean}
-
Checks if the given key exists in the Sound Cache.
Parameters:
Name Type Description keystring Asset key of the sound file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkTextKey(key) → {boolean}
-
Checks if the given key exists in the Text Cache.
Parameters:
Name Type Description keystring Asset key of the text file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkTextureKey(key) → {boolean}
-
Checks if the given key exists in the Texture Cache.
Parameters:
Name Type Description keystring Asset key of the image to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkTilemapKey(key) → {boolean}
-
Checks if the given key exists in the Tilemap Cache.
Parameters:
Name Type Description keystring Asset key of the Tilemap to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
checkUrl(url) → {boolean}
-
Checks if the given URL has been loaded into the Cache.
Parameters:
Name Type Description urlstring The url to check for in the cache.
- Source:
Returns:
True if the url exists, otherwise false.
- Type
- boolean
-
checkXMLKey(key) → {boolean}
-
Checks if the given key exists in the XML Cache.
Parameters:
Name Type Description keystring Asset key of the XML file to check is in the Cache.
- Source:
Returns:
True if the key exists, otherwise false.
- Type
- boolean
-
decodedSound(key, data)
-
Add a new decoded sound.
Parameters:
Name Type Description keystring Asset key for the sound.
dataobject Extra sound data.
- Source:
-
destroy()
-
Clears the cache. Removes every local cache object reference.
- Source:
-
getBinary(key) → {object}
-
Get binary data by key.
Parameters:
Name Type Description keystring Asset key of the binary data object to retrieve from the Cache.
- Source:
Returns:
The binary data object.
- Type
- object
-
getBitmapData(key) → {Phaser.BitmapData}
-
Get a BitmapData object from the cache by its key.
Parameters:
Name Type Description keystring Asset key of the BitmapData object to retrieve from the Cache.
- Source:
Returns:
The requested BitmapData object if found, or null if not.
- Type
- Phaser.BitmapData
-
getBitmapFont(key) → {Phaser.BitmapFont}
-
Get a BitmapFont object from the cache by its key.
Parameters:
Name Type Description keystring Asset key of the BitmapFont object to retrieve from the Cache.
- Source:
Returns:
The requested BitmapFont object if found, or null if not.
- Type
- Phaser.BitmapFont
-
getCanvas(key) → {object}
-
Get a canvas object from the cache by its key.
Parameters:
Name Type Description keystring Asset key of the canvas to retrieve from the Cache.
- Source:
Returns:
The canvas object.
- Type
- object
-
getFrame(key) → {Phaser.Frame}
-
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 Description keystring Asset key of the frame data to retrieve from the Cache.
- Source:
Returns:
The frame data.
- Type
- Phaser.Frame
-
getFrameByIndex(key) → {Phaser.Frame}
-
Get a single frame out of a frameData set by key.
Parameters:
Name Type Description keystring Asset key of the frame data to retrieve from the Cache.
- Source:
Returns:
The frame object.
- Type
- Phaser.Frame
-
getFrameByName(key) → {Phaser.Frame}
-
Get a single frame out of a frameData set by key.
Parameters:
Name Type Description keystring Asset key of the frame data to retrieve from the Cache.
- Source:
Returns:
The frame object.
- Type
- Phaser.Frame
-
getFrameCount(key) → {number}
-
Get the number of frames in this image.
Parameters:
Name Type Description keystring Asset key of the image you want.
- Source:
Returns:
Then number of frames. 0 if the image is not found.
- Type
- number
-
getFrameData(key, map) → {Phaser.FrameData}
-
Get frame data by key.
Parameters:
Name Type Argument Default Description keystring Asset key of the frame data to retrieve from the Cache.
mapstring <optional>
Phaser.Cache.IMAGE The asset map to get the frameData from, for example
Phaser.Cache.IMAGE.- Source:
Returns:
The frame data.
- Type
- Phaser.FrameData
-
getImage(key) → {object}
-
Get image data by key.
Parameters:
Name Type Description keystring Asset key of the image to retrieve from the Cache.
- Source:
Returns:
The image data if found in the Cache, otherwise
null.- Type
- object
-
getJSON(key) → {object}
-
Get a JSON object by key from the cache.
Parameters:
Name Type Description keystring Asset key of the json object to retrieve from the Cache.
- Source:
Returns:
The JSON object.
- Type
- object
-
getKeys(type) → {Array}
-
Gets all keys used by the Cache for the given data type.
Parameters:
Name Type Argument Default Description typenumber <optional>
Phaser.Cache.IMAGE The type of Cache keys you wish to get. Can be Cache.CANVAS, Cache.IMAGE, Cache.SOUND, etc.
- Source:
Returns:
The array of item keys.
- Type
- Array
-
getPhysicsData(key, object, fixtureKey) → {object}
-
Get a physics data object from the cache by its key. 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 keystring Asset key of the physics data object to retrieve from the Cache.
objectstring <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.
fixtureKeystring Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
- Source:
Returns:
The requested physics object data if found.
- Type
- object
-
getSound(key) → {Phaser.Sound}
-
Get sound by key.
Parameters:
Name Type Description keystring Asset key of the sound to retrieve from the Cache.
- Source:
Returns:
The sound object.
- Type
- Phaser.Sound
-
getSoundData(key) → {object}
-
Get sound data by key.
Parameters:
Name Type Description keystring Asset key of the sound to retrieve from the Cache.
- Source:
Returns:
The sound data.
- Type
- object
-
getText(key) → {object}
-
Get text data by key.
Parameters:
Name Type Description keystring Asset key of the text data to retrieve from the Cache.
- Source:
Returns:
The text data.
- Type
- object
-
getTexture(key) → {Phaser.RenderTexture}
-
Get a RenderTexture by key.
Parameters:
Name Type Description keystring Asset key of the RenderTexture to retrieve from the Cache.
- Source:
Returns:
The RenderTexture object.
- Type
- Phaser.RenderTexture
-
getTextureFrame(key) → {Phaser.Frame}
-
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 keystring Asset key of the frame to retrieve from the Cache.
- Source:
Returns:
The frame data.
- Type
- Phaser.Frame
-
getTilemapData(key) → {Object}
-
Get tilemap data by key.
Parameters:
Name Type Description keystring Asset key of the tilemap data to retrieve from the Cache.
- Source:
Returns:
The raw tilemap data in CSV or JSON format.
- Type
- Object
-
getUrl(url) → {object}
-
Get a cached object by the URL.
Parameters:
Name Type Description urlstring The url for the object loaded to get from the cache.
- Source:
Returns:
The cached object.
- Type
- object
-
getXML(key) → {object}
-
Get a XML object by key from the cache.
Parameters:
Name Type Description keystring Asset key of the XML object to retrieve from the Cache.
- Source:
Returns:
The XML object.
- Type
- object
-
isSoundDecoded(key) → {boolean}
-
Check if the given sound has finished decoding.
Parameters:
Name Type Description keystring Asset key of the sound in the Cache.
- Source:
Returns:
The decoded state of the Sound object.
- Type
- boolean
-
isSoundReady(key) → {boolean}
-
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 keystring Asset key of the sound in the Cache.
- Source:
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 keystring Asset key for the sound.
- Source:
-
reloadSoundComplete(key)
-
Fires the onSoundUnlock event when the sound has completed reloading.
Parameters:
Name Type Description keystring Asset key for the sound.
- Source:
-
removeBinary(key)
-
Removes a binary file from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeBitmapData(key)
-
Removes a bitmap data from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeBitmapFont(key)
-
Removes a bitmap font from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeCanvas(key)
-
Removes a canvas from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeImage(key, removeFromPixi)
-
Removes an image from the cache and optionally from the Pixi.BaseTextureCache as well.
Parameters:
Name Type Argument Default Description keystring Key of the asset you want to remove.
removeFromPixiboolean <optional>
true Should this image also be removed from the Pixi BaseTextureCache?
- Source:
-
removeJSON(key)
-
Removes a json object from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removePhysics(key)
-
Removes a physics data file from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeSound(key)
-
Removes a sound from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeText(key)
-
Removes a text from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeTilemap(key)
-
Removes a tilemap from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
removeXML(key)
-
Removes a xml object from the cache.
Parameters:
Name Type Description keystring Key of the asset you want to remove.
- Source:
-
updateFrameData(key, frameData)
-
Replaces a set of frameData with a new Phaser.FrameData object.
Parameters:
Name Type Description keystring The unique key by which you will reference this object.
frameDatanumber The new FrameData.
- Source:
-
updateSound(key)
-
Updates the sound object in the cache.
Parameters:
Name Type Description keystring Asset key for the sound.
- Source: