Class: Cache

Phaser. Cache

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.

new Cache(game)

Phaser.Cache constructor.

Parameters:
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source:

Members

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

onSoundUnlock

Properties:
Name Type Description
onSoundUnlock Phaser.Signal

This event is dispatched when the sound system is unlocked via a touch event on cellular devices.

Source:

Methods

addBinary(key, binaryData)

Add a binary object in to the cache.

Parameters:
Name Type Description
key string

Asset key for this binary data.

binaryData object

The binary object to be addded to the cache.

Source:

addBitmapData(key, bitmapData) → {Phaser.BitmapData}

Add a BitmapData object in to the cache.

Parameters:
Name Type Description
key string

Asset key for this BitmapData.

bitmapData Phaser.BitmapData

The BitmapData object to be addded to the cache.

Source:
Returns:

The BitmapData object to be addded to the cache.

Type
Phaser.BitmapData

addBitmapFont(key, url, data, xmlData)

Add a new Bitmap Font.

Parameters:
Name Type Description
key string

The unique key by which you will reference this object.

url string

URL of this font xml file.

data object

Extra font data.

xmlData object

Texture atlas frames data.

Source:

addCanvas(key, canvas, context)

Add a new canvas object in to the cache.

Parameters:
Name Type Description
key string

Asset key for this canvas.

canvas HTMLCanvasElement

Canvas DOM element.

context CanvasRenderingContext2D

Render context of this canvas.

Source:

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)

Add a new image.

Parameters:
Name Type Description
key string

The unique key by which you will reference this object.

url string

URL of this image file.

data object

Extra image data.

Source:

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
key string

The unique key by which you will reference this object.

texture Phaser.Texture

The texture to use as the base of the RenderTexture.

Source:

addSound(key, url, data, webAudio, audioTag)

Add a new sound.

Parameters:
Name Type Description
key string

Asset key for the sound.

url string

URL of this sound file.

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:

addSpriteSheet(key, url, data, frameWidth, frameHeight, frameMax, margin, spacing)

Add a new sprite sheet in to the cache.

Parameters:
Name Type Argument Default Description
key string

The unique key by which you will reference this object.

url string

URL of this sprite sheet file.

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.

Source:

addText(key, url, data)

Add a new text data.

Parameters:
Name Type Description
key string

Asset key for the text data.

url string

URL of this text data file.

data object

Extra text data.

Source:

addTextureAtlas(key, url, data, atlasData, format)

Add a new texture atlas.

Parameters:
Name Type Description
key string

The unique key by which you will reference this object.

url string

URL of this texture atlas file.

data object

Extra texture atlas data.

atlasData object

Texture atlas frames data.

format number

The format of the texture atlas.

Source:

addTilemap(key, url, mapData, format)

Add a new tilemap.

Parameters:
Name Type Description
key string

The unique key by which you will reference this object.

url string

URL of the tilemap image.

mapData object

The tilemap data object (either a CSV or JSON file).

format number

The format of the tilemap data.

Source:

checkImageKey(key) → {boolean}

Checks if an image key exists.

Parameters:
Name Type Description
key string

Asset key of the image 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
key string

Asset key for the sound.

data object

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
key string

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
key string

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

getCanvas(key) → {object}

Get a canvas object from the cache by its key.

Parameters:
Name Type Description
key string

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
key string

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
key string

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
key string

Asset key of the frame data to retrieve from the Cache.

Source:
Returns:

The frame object.

Type
Phaser.Frame

getFrameData(key) → {Phaser.FrameData}

Get frame data by key.

Parameters:
Name Type Description
key string

Asset key of the frame data to retrieve from the Cache.

Source:
Returns:

The frame data.

Type
Phaser.FrameData

getImage(key) → {object}

Get image data by key.

Parameters:
Name Type Description
key string

Asset key of the image to retrieve from the Cache.

Source:
Returns:

The image data.

Type
object

getImageKeys() → {Array}

Returns an array containing all of the keys of Images in the Cache.

Source:
Returns:

The string based keys in the Cache.

Type
Array

getKeys(array) → {Array}

Get the cache keys from a given array of objects. Normally you don't call this directly but instead use getImageKeys, getSoundKeys, etc.

Parameters:
Name Type Description
array Array

An array of items to return the keys for.

Source:
Returns:

The array of item keys.

Type
Array

getSound(key) → {Phaser.Sound}

Get sound by key.

Parameters:
Name Type Description
key string

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
key string

Asset key of the sound to retrieve from the Cache.

Source:
Returns:

The sound data.

Type
object

getSoundKeys() → {Array}

Returns an array containing all of the keys of Sounds in the Cache.

Source:
Returns:

The string based keys in the Cache.

Type
Array

getText(key) → {object}

Get text data by key.

Parameters:
Name Type Description
key string

Asset key of the text data to retrieve from the Cache.

Source:
Returns:

The text data.

Type
object

getTextKeys() → {Array}

Returns an array containing all of the keys of Text Files in the Cache.

Source:
Returns:

The string based keys in the Cache.

Type
Array

getTexture(key) → {Phaser.RenderTexture}

Get a RenderTexture by key.

Parameters:
Name Type Description
key string

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
key string

Asset key of the frame to retrieve from the Cache.

Source:
Returns:

The frame data.

Type
Phaser.Frame

getTilemap(key) → {Object}

Get tilemap data by key.

Parameters:
Name Type Description
key string

Asset key of the tilemap data to retrieve from the Cache.

Source:
Returns:

The raw tilemap data in CSV or JSON format.

Type
Object

isSoundDecoded(key) → {boolean}

Check if the given sound has finished decoding.

Parameters:
Name Type Description
key string

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
key string

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

isSpriteSheet(key) → {boolean}

Check whether an image asset is sprite sheet or not.

Parameters:
Name Type Description
key string

Asset key of the sprite sheet you want.

Source:
Returns:

True if the image is a sprite sheet.

Type
boolean

reloadSound(key)

Reload a sound.

Parameters:
Name Type Description
key string

Asset key for the sound.

Source:

reloadSoundComplete(key)

Fires the onSoundUnlock event when the sound has completed reloading.

Parameters:
Name Type Description
key string

Asset key for the sound.

Source:

removeCanvas(key)

Removes a canvas from the cache.

Parameters:
Name Type Description
key string

Key of the asset you want to remove.

Source:

removeImage(key)

Removes an image from the cache.

Parameters:
Name Type Description
key string

Key of the asset you want to remove.

Source:

removeSound(key)

Removes a sound from the cache.

Parameters:
Name Type Description
key string

Key of the asset you want to remove.

Source:

removeText(key)

Removes a text from the cache.

Parameters:
Name Type Description
key string

Key of the asset you want to remove.

Source:

updateSound(key)

Updates the sound object in the cache.

Parameters:
Name Type Description
key string

Asset key for the sound.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Feb 08 2014 07:19:42 GMT-0000 (GMT) using the DocStrap template.