2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-10-05 02:20:28 +00:00
|
|
|
* A game only has one instance of a Cache and it is used to store all externally loaded assets such as images, sounds
|
2014-09-16 16:35:08 +00:00
|
|
|
* and data files as a result of Loader calls. Cached items use string based keys for look-up.
|
2014-10-05 02:20:28 +00:00
|
|
|
*
|
2013-12-20 18:27:36 +00:00
|
|
|
* @class Phaser.Cache
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
|
|
|
Phaser.Cache = function (game) {
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {Phaser.Game} game - Local reference to game.
|
|
|
|
*/
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
/**
|
2014-09-15 12:51:17 +00:00
|
|
|
* @property {object} _canvases - Canvas key-value container.
|
2013-11-25 04:40:04 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._canvases = {};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {object} _images - Image key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._images = {};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {object} _textures - RenderTexture key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-11 01:57:36 +00:00
|
|
|
this._textures = {};
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {object} _sounds - Sound key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._sounds = {};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {object} _text - Text key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._text = {};
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
2014-09-15 12:51:17 +00:00
|
|
|
* @property {object} _json - JSOIN key-value container.
|
2014-02-21 18:48:06 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._json = {};
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _xml - XML key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._xml = {};
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _physics - Physics data key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._physics = {};
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {object} _tilemaps - Tilemap key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-12 03:24:01 +00:00
|
|
|
this._tilemaps = {};
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
/**
|
2013-12-20 18:27:36 +00:00
|
|
|
* @property {object} _binary - Binary file key-value container.
|
2013-10-11 03:42:11 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2013-12-20 18:27:36 +00:00
|
|
|
this._binary = {};
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-11-13 20:57:09 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _bitmapDatas - BitmapData key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._bitmapDatas = {};
|
|
|
|
|
2014-02-14 16:38:06 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _bitmapFont - BitmapFont key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._bitmapFont = {};
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _urlMap - Maps URLs to resources.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._urlMap = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Image} _urlResolver - Used to resolve URLs to the absolute path.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._urlResolver = new Image();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {string} _urlTemp - Temporary variable to hold a resolved url.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._urlTemp = null;
|
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
this.addDefaultImage();
|
2013-11-21 04:59:54 +00:00
|
|
|
this.addMissingImage();
|
2013-09-10 19:40:34 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-11-25 04:40:04 +00:00
|
|
|
* @property {Phaser.Signal} onSoundUnlock - This event is dispatched when the sound system is unlocked via a touch event on cellular devices.
|
|
|
|
*/
|
|
|
|
this.onSoundUnlock = new Phaser.Signal();
|
2013-09-11 10:33:27 +00:00
|
|
|
|
2014-05-19 10:34:14 +00:00
|
|
|
/**
|
|
|
|
* @property {array} _cacheMap - Const to cache object look-up array.
|
|
|
|
*/
|
|
|
|
this._cacheMap = [];
|
|
|
|
|
|
|
|
this._cacheMap[Phaser.Cache.CANVAS] = this._canvases;
|
|
|
|
this._cacheMap[Phaser.Cache.IMAGE] = this._images;
|
|
|
|
this._cacheMap[Phaser.Cache.TEXTURE] = this._textures;
|
|
|
|
this._cacheMap[Phaser.Cache.SOUND] = this._sounds;
|
|
|
|
this._cacheMap[Phaser.Cache.TEXT] = this._text;
|
|
|
|
this._cacheMap[Phaser.Cache.PHYSICS] = this._physics;
|
|
|
|
this._cacheMap[Phaser.Cache.TILEMAP] = this._tilemaps;
|
|
|
|
this._cacheMap[Phaser.Cache.BINARY] = this._binary;
|
|
|
|
this._cacheMap[Phaser.Cache.BITMAPDATA] = this._bitmapDatas;
|
|
|
|
this._cacheMap[Phaser.Cache.BITMAPFONT] = this._bitmapFont;
|
|
|
|
this._cacheMap[Phaser.Cache.JSON] = this._json;
|
2014-09-18 23:22:00 +00:00
|
|
|
this._cacheMap[Phaser.Cache.XML] = this._xml;
|
2014-05-19 10:34:14 +00:00
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
};
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.CANVAS = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.IMAGE = 2;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.TEXTURE = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.SOUND = 4;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.TEXT = 5;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.PHYSICS = 6;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.TILEMAP = 7;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.BINARY = 8;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.BITMAPDATA = 9;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.BITMAPFONT = 10;
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.JSON = 11;
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.XML = 12;
|
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
Phaser.Cache.prototype = {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-02 14:05:55 +00:00
|
|
|
* Add a new canvas object in to the cache.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.Cache#addCanvas
|
|
|
|
* @param {string} key - Asset key for this canvas.
|
|
|
|
* @param {HTMLCanvasElement} canvas - Canvas DOM element.
|
|
|
|
* @param {CanvasRenderingContext2D} context - Render context of this canvas.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
addCanvas: function (key, canvas, context) {
|
|
|
|
|
|
|
|
this._canvases[key] = { canvas: canvas, context: context };
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-12-20 18:27:36 +00:00
|
|
|
/**
|
|
|
|
* Add a binary object in to the cache.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2013-12-20 18:27:36 +00:00
|
|
|
* @method Phaser.Cache#addBinary
|
|
|
|
* @param {string} key - Asset key for this binary data.
|
|
|
|
* @param {object} binaryData - The binary object to be addded to the cache.
|
|
|
|
*/
|
|
|
|
addBinary: function (key, binaryData) {
|
|
|
|
|
|
|
|
this._binary[key] = binaryData;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-13 20:57:09 +00:00
|
|
|
/**
|
|
|
|
* Add a BitmapData object in to the cache.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2013-11-13 20:57:09 +00:00
|
|
|
* @method Phaser.Cache#addBitmapData
|
|
|
|
* @param {string} key - Asset key for this BitmapData.
|
|
|
|
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
|
2014-10-01 02:10:13 +00:00
|
|
|
* @param {Phaser.FrameData} [frameData] - Optional FrameData set associated with the given BitmapData.
|
2013-11-13 20:57:09 +00:00
|
|
|
* @return {Phaser.BitmapData} The BitmapData object to be addded to the cache.
|
|
|
|
*/
|
2014-10-01 02:10:13 +00:00
|
|
|
addBitmapData: function (key, bitmapData, frameData) {
|
2013-11-13 20:57:09 +00:00
|
|
|
|
2014-10-01 02:10:13 +00:00
|
|
|
bitmapData.key = key;
|
|
|
|
|
|
|
|
this._bitmapDatas[key] = { data: bitmapData, frameData: frameData };
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
return bitmapData;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
/**
|
2013-10-02 14:05:55 +00:00
|
|
|
* Add a new Phaser.RenderTexture in to the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addRenderTexture
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
2014-10-21 21:43:42 +00:00
|
|
|
* @param {Phaser.RenderTexture} texture - The texture to use as the base of the RenderTexture.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-09-11 01:57:36 +00:00
|
|
|
addRenderTexture: function (key, texture) {
|
|
|
|
|
2013-10-03 01:38:35 +00:00
|
|
|
var frame = new Phaser.Frame(0, 0, 0, texture.width, texture.height, '', '');
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
this._textures[key] = { texture: texture, frame: frame };
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-10-02 14:05:55 +00:00
|
|
|
* Add a new sprite sheet in to the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addSpriteSheet
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of this sprite sheet file.
|
|
|
|
* @param {object} data - Extra sprite sheet data.
|
|
|
|
* @param {number} frameWidth - Width of the sprite sheet.
|
|
|
|
* @param {number} frameHeight - Height of the sprite sheet.
|
2013-12-13 14:04:14 +00:00
|
|
|
* @param {number} [frameMax=-1] - How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly.
|
|
|
|
* @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
|
|
|
|
* @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-12-13 14:04:14 +00:00
|
|
|
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax, margin, spacing) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
this._images[key] = { url: url, data: data, frameWidth: frameWidth, frameHeight: frameHeight, margin: margin, spacing: spacing };
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2014-07-11 17:02:40 +00:00
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2013-12-13 14:04:14 +00:00
|
|
|
this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax, margin, spacing);
|
2013-08-30 01:18:00 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
2014-02-14 23:51:49 +00:00
|
|
|
* Add a new tilemap to the Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addTilemap
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of the tilemap image.
|
2013-12-18 16:56:14 +00:00
|
|
|
* @param {object} mapData - The tilemap data object (either a CSV or JSON file).
|
2013-10-02 14:05:55 +00:00
|
|
|
* @param {number} format - The format of the tilemap data.
|
|
|
|
*/
|
2013-10-11 05:30:28 +00:00
|
|
|
addTilemap: function (key, url, mapData, format) {
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2013-10-11 17:18:27 +00:00
|
|
|
this._tilemaps[key] = { url: url, data: mapData, format: format };
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._tilemaps[key];
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2014-02-14 23:51:49 +00:00
|
|
|
* Add a new texture atlas to the Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addTextureAtlas
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of this texture atlas file.
|
|
|
|
* @param {object} data - Extra texture atlas data.
|
|
|
|
* @param {object} atlasData - Texture atlas frames data.
|
|
|
|
* @param {number} format - The format of the texture atlas.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
addTextureAtlas: function (key, url, data, atlasData, format) {
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
this._images[key] = { url: url, data: data };
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2014-07-11 17:02:40 +00:00
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
|
|
|
|
{
|
2013-10-03 00:21:08 +00:00
|
|
|
this._images[key].frameData = Phaser.AnimationParser.JSONData(this.game, atlasData, key);
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
2013-08-29 21:53:55 +00:00
|
|
|
else if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
|
|
|
|
{
|
2013-10-03 00:21:08 +00:00
|
|
|
this._images[key].frameData = Phaser.AnimationParser.JSONDataHash(this.game, atlasData, key);
|
2013-08-29 21:53:55 +00:00
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
else if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
|
|
|
{
|
2013-10-03 00:21:08 +00:00
|
|
|
this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
/**
|
2014-02-14 23:51:49 +00:00
|
|
|
* Add a new Bitmap Font to the Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addBitmapFont
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of this font xml file.
|
|
|
|
* @param {object} data - Extra font data.
|
2014-02-14 04:34:57 +00:00
|
|
|
* @param {object} xmlData - Texture atlas frames data.
|
|
|
|
* @param {number} [xSpacing=0] - If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
|
|
|
|
* @param {number} [ySpacing=0] - If you'd like to add additional vertical spacing between the lines then set the pixel value here.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2014-02-14 04:34:57 +00:00
|
|
|
addBitmapFont: function (key, url, data, xmlData, xSpacing, ySpacing) {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
this._images[key] = { url: url, data: data };
|
2013-09-10 22:51:35 +00:00
|
|
|
|
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2014-07-11 17:02:40 +00:00
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-02-14 04:34:57 +00:00
|
|
|
Phaser.LoaderParser.bitmapFont(this.game, xmlData, key, xSpacing, ySpacing);
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2014-08-28 02:52:26 +00:00
|
|
|
this._bitmapFont[key] = PIXI.BitmapText.fonts[key];
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._bitmapFont[key];
|
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* Add a new physics data object to the Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addTilemap
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of the physics json data.
|
|
|
|
* @param {object} JSONData - The physics data object (a JSON file).
|
|
|
|
* @param {number} format - The format of the physics data.
|
|
|
|
*/
|
|
|
|
addPhysicsData: function (key, url, JSONData, format) {
|
|
|
|
|
|
|
|
this._physics[key] = { url: url, data: JSONData, format: format };
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._physics[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
2013-09-10 10:09:25 +00:00
|
|
|
/**
|
2013-11-21 04:59:54 +00:00
|
|
|
* Adds a default image to be used in special cases such as WebGL Filters. Is mapped to the key __default.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addDefaultImage
|
2014-02-14 23:51:49 +00:00
|
|
|
* @protected
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-09-10 10:09:25 +00:00
|
|
|
addDefaultImage: function () {
|
|
|
|
|
2013-10-03 22:20:24 +00:00
|
|
|
var img = new Image();
|
2013-11-21 04:59:54 +00:00
|
|
|
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==";
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2014-08-28 16:01:01 +00:00
|
|
|
this._images['__default'] = { url: null, data: img };
|
2013-10-03 22:20:24 +00:00
|
|
|
this._images['__default'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
|
2014-08-28 16:01:01 +00:00
|
|
|
this._images['__default'].frameData = new Phaser.FrameData();
|
|
|
|
this._images['__default'].frameData.addFrame(new Phaser.Frame(0, 0, 0, 32, 32, null, this.game.rnd.uuid()));
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2013-10-03 22:20:24 +00:00
|
|
|
PIXI.BaseTextureCache['__default'] = new PIXI.BaseTexture(img);
|
|
|
|
PIXI.TextureCache['__default'] = new PIXI.Texture(PIXI.BaseTextureCache['__default']);
|
2013-09-10 10:09:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-21 04:59:54 +00:00
|
|
|
/**
|
|
|
|
* Adds an image to be used when a key is wrong / missing. Is mapped to the key __missing.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addMissingImage
|
2014-02-14 23:51:49 +00:00
|
|
|
* @protected
|
2013-11-21 04:59:54 +00:00
|
|
|
*/
|
|
|
|
addMissingImage: function () {
|
|
|
|
|
|
|
|
var img = new Image();
|
|
|
|
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
|
|
|
|
|
2014-08-28 16:01:01 +00:00
|
|
|
this._images['__missing'] = { url: null, data: img };
|
2013-11-21 04:59:54 +00:00
|
|
|
this._images['__missing'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
|
2014-08-28 16:01:01 +00:00
|
|
|
this._images['__missing'].frameData = new Phaser.FrameData();
|
|
|
|
this._images['__missing'].frameData.addFrame(new Phaser.Frame(0, 0, 0, 32, 32, null, this.game.rnd.uuid()));
|
2013-11-21 04:59:54 +00:00
|
|
|
|
|
|
|
PIXI.BaseTextureCache['__missing'] = new PIXI.BaseTexture(img);
|
|
|
|
PIXI.TextureCache['__missing'] = new PIXI.Texture(PIXI.BaseTextureCache['__missing']);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
/**
|
|
|
|
* Add a new text data.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addText
|
2014-03-23 07:59:28 +00:00
|
|
|
* @param {string} key - Asset key for the text data.
|
2013-10-11 03:42:11 +00:00
|
|
|
* @param {string} url - URL of this text data file.
|
|
|
|
* @param {object} data - Extra text data.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-10-11 03:42:11 +00:00
|
|
|
addText: function (key, url, data) {
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
this._text[key] = { url: url, data: data };
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._text[key];
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
},
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
|
|
|
* Add a new json object into the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addJSON
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key for the json data.
|
|
|
|
* @param {string} url - URL of this json data file.
|
|
|
|
* @param {object} data - Extra json data.
|
2014-02-21 18:48:06 +00:00
|
|
|
*/
|
|
|
|
addJSON: function (key, url, data) {
|
|
|
|
|
|
|
|
this._json[key] = { url: url, data: data };
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._json[key];
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* Add a new xml object into the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addXML
|
|
|
|
* @param {string} key - Asset key for the xml file.
|
|
|
|
* @param {string} url - URL of this xml file.
|
|
|
|
* @param {object} data - Extra text data.
|
|
|
|
*/
|
|
|
|
addXML: function (key, url, data) {
|
|
|
|
|
|
|
|
this._xml[key] = { url: url, data: data };
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2014-07-02 04:32:27 +00:00
|
|
|
* Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addImage
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {string} url - URL of this image file.
|
|
|
|
* @param {object} data - Extra image data.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
addImage: function (key, url, data) {
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
this._images[key] = { url: url, data: data };
|
2013-10-24 20:21:00 +00:00
|
|
|
|
|
|
|
this._images[key].frame = new Phaser.Frame(0, 0, 0, data.width, data.height, key, this.game.rnd.uuid());
|
2014-07-22 08:24:53 +00:00
|
|
|
this._images[key].frameData = new Phaser.FrameData();
|
|
|
|
this._images[key].frameData.addFrame(new Phaser.Frame(0, 0, 0, data.width, data.height, url, this.game.rnd.uuid()));
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2014-07-11 17:02:40 +00:00
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._images[key];
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-07-02 04:32:27 +00:00
|
|
|
* Adds a Sound file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addSound
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
* @param {string} url - URL of this sound file.
|
|
|
|
* @param {object} data - Extra sound data.
|
|
|
|
* @param {boolean} webAudio - True if the file is using web audio.
|
|
|
|
* @param {boolean} audioTag - True if the file is using legacy HTML audio.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
addSound: function (key, url, data, webAudio, audioTag) {
|
|
|
|
|
2013-09-03 16:07:05 +00:00
|
|
|
webAudio = webAudio || true;
|
|
|
|
audioTag = audioTag || false;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
var decoded = false;
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (audioTag)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
decoded = true;
|
|
|
|
}
|
|
|
|
|
2013-12-31 03:37:11 +00:00
|
|
|
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag, locked: this.game.sound.touchLocked };
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlMap[this._resolveUrl(url)] = this._sounds[key];
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-07-02 04:32:27 +00:00
|
|
|
* Reload a Sound file from the server.
|
2013-12-13 14:04:14 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.Cache#reloadSound
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
reloadSound: function (key) {
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
this._sounds[key].data.src = this._sounds[key].url;
|
|
|
|
|
|
|
|
this._sounds[key].data.addEventListener('canplaythrough', function () {
|
|
|
|
return _this.reloadSoundComplete(key);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
this._sounds[key].data.load();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-12-13 14:04:14 +00:00
|
|
|
* Fires the onSoundUnlock event when the sound has completed reloading.
|
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.Cache#reloadSoundComplete
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
reloadSoundComplete: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
this._sounds[key].locked = false;
|
|
|
|
this.onSoundUnlock.dispatch(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-12-13 14:04:14 +00:00
|
|
|
* Updates the sound object in the cache.
|
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.Cache#updateSound
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
updateSound: function (key, property, value) {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
this._sounds[key][property] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Add a new decoded sound.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#decodedSound
|
2013-11-25 04:40:04 +00:00
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
* @param {object} data - Extra sound data.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
decodedSound: function (key, data) {
|
|
|
|
|
|
|
|
this._sounds[key].data = data;
|
|
|
|
this._sounds[key].decoded = true;
|
|
|
|
this._sounds[key].isDecoding = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get a canvas object from the cache by its key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getCanvas
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the canvas to retrieve from the Cache.
|
|
|
|
* @return {object} The canvas object.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
getCanvas: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._canvases[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._canvases[key].canvas;
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getCanvas: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a BitmapData object from the cache by its key.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getBitmapData
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the BitmapData object to retrieve from the Cache.
|
2013-11-13 20:57:09 +00:00
|
|
|
* @return {Phaser.BitmapData} The requested BitmapData object if found, or null if not.
|
|
|
|
*/
|
|
|
|
getBitmapData: function (key) {
|
|
|
|
|
|
|
|
if (this._bitmapDatas[key])
|
|
|
|
{
|
2014-10-01 02:10:13 +00:00
|
|
|
return this._bitmapDatas[key].data;
|
2013-11-13 20:57:09 +00:00
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getBitmapData: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-11-13 20:57:09 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 16:38:06 +00:00
|
|
|
/**
|
|
|
|
* Get a BitmapFont object from the cache by its key.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getBitmapFont
|
|
|
|
* @param {string} key - Asset key of the BitmapFont object to retrieve from the Cache.
|
|
|
|
* @return {Phaser.BitmapFont} The requested BitmapFont object if found, or null if not.
|
|
|
|
*/
|
|
|
|
getBitmapFont: function (key) {
|
|
|
|
|
|
|
|
if (this._bitmapFont[key])
|
|
|
|
{
|
|
|
|
return this._bitmapFont[key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getBitmapFont: Invalid key: "' + key + '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
2014-03-31 08:19:08 +00:00
|
|
|
* 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.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getPhysicsData
|
|
|
|
* @param {string} key - Asset key of the physics data object to retrieve from the Cache.
|
|
|
|
* @param {string} [object=null] - If specified it will return just the physics object that is part of the given key, if null it will return them all.
|
2014-03-31 08:19:08 +00:00
|
|
|
* @param {string} fixtureKey - Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
|
2014-02-14 23:51:49 +00:00
|
|
|
* @return {object} The requested physics object data if found.
|
|
|
|
*/
|
2014-03-31 08:19:08 +00:00
|
|
|
getPhysicsData: function (key, object, fixtureKey) {
|
2014-02-14 23:51:49 +00:00
|
|
|
|
|
|
|
if (typeof object === 'undefined' || object === null)
|
|
|
|
{
|
|
|
|
// Get 'em all
|
|
|
|
if (this._physics[key])
|
|
|
|
{
|
|
|
|
return this._physics[key].data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getPhysicsData: Invalid key: "' + key + '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this._physics[key] && this._physics[key].data[object])
|
|
|
|
{
|
2014-04-01 00:30:20 +00:00
|
|
|
var fixtures = this._physics[key].data[object];
|
2014-03-31 08:19:08 +00:00
|
|
|
|
|
|
|
//try to find a fixture by it's fixture key if given
|
|
|
|
if (fixtures && fixtureKey)
|
|
|
|
{
|
2014-04-01 00:30:20 +00:00
|
|
|
for (var fixture in fixtures)
|
2014-03-31 08:19:08 +00:00
|
|
|
{
|
2014-04-01 00:30:20 +00:00
|
|
|
// This contains the fixture data of a polygon or a circle
|
|
|
|
fixture = fixtures[fixture];
|
|
|
|
|
|
|
|
// Test the key
|
|
|
|
if (fixture.fixtureKey === fixtureKey)
|
2014-03-31 08:19:08 +00:00
|
|
|
{
|
|
|
|
return fixture;
|
|
|
|
}
|
2014-04-01 00:30:20 +00:00
|
|
|
|
2014-03-31 08:19:08 +00:00
|
|
|
}
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2014-04-01 00:30:20 +00:00
|
|
|
// We did not find the requested fixture
|
2014-03-31 08:19:08 +00:00
|
|
|
console.warn('Phaser.Cache.getPhysicsData: Could not find given fixtureKey: "' + fixtureKey + ' in ' + key + '"');
|
2014-04-01 00:30:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-31 08:19:08 +00:00
|
|
|
return fixtures;
|
|
|
|
}
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getPhysicsData: Invalid key/object: "' + key + ' / ' + object + '"');
|
|
|
|
}
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-10 10:09:25 +00:00
|
|
|
/**
|
2014-05-19 10:34:14 +00:00
|
|
|
* Checks if a key for the given cache object type exists.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2014-05-19 10:34:14 +00:00
|
|
|
* @method Phaser.Cache#checkKey
|
|
|
|
* @param {number} type - The Cache type to check against. I.e. Phaser.Cache.CANVAS, Phaser.Cache.IMAGE, Phaser.Cache.JSON, etc.
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the image to check is in the Cache.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-05-19 10:34:14 +00:00
|
|
|
checkKey: function (type, key) {
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2014-05-19 10:34:14 +00:00
|
|
|
if (this._cacheMap[type][key])
|
2013-09-10 10:09:25 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-05-19 10:34:14 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Canvas Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkCanvasKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the canvas to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkCanvasKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.CANVAS, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Image Cache. Note that this also includes Texture Atlases, Sprite Sheets and Retro Fonts.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkImageKey
|
|
|
|
* @param {string} key - Asset key of the image to check is in the Cache.
|
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkImageKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.IMAGE, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Texture Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTextureKey
|
|
|
|
* @param {string} key - Asset key of the image to check is in the Cache.
|
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkTextureKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TEXTURE, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Sound Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkSoundKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the sound file to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkSoundKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.SOUND, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Text Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTextKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the text file to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkTextKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TEXT, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Physics Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkPhysicsKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the physics data file to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkPhysicsKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.PHYSICS, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Tilemap Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTilemapKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the Tilemap to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkTilemapKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TILEMAP, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Binary Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBinaryKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the binary file to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkBinaryKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BINARY, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the BitmapData Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBitmapDataKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the BitmapData to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkBitmapDataKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BITMAPDATA, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the BitmapFont Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBitmapFontKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the BitmapFont to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkBitmapFontKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BITMAPFONT, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the JSON Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkJSONKey
|
2014-09-18 23:22:00 +00:00
|
|
|
* @param {string} key - Asset key of the JSON file to check is in the Cache.
|
2014-05-19 10:34:14 +00:00
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkJSONKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.JSON, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the XML Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkXMLKey
|
|
|
|
* @param {string} key - Asset key of the XML file to check is in the Cache.
|
|
|
|
* @return {boolean} True if the key exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkXMLKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.XML, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given URL has been loaded into the Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkUrl
|
|
|
|
* @param {string} url - The url to check for in the cache.
|
|
|
|
* @return {boolean} True if the url exists, otherwise false.
|
|
|
|
*/
|
|
|
|
checkUrl: function (url) {
|
|
|
|
|
|
|
|
if (this._urlMap[this._resolveUrl(url)])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get image data by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getImage
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the image to retrieve from the Cache.
|
2014-09-03 10:11:48 +00:00
|
|
|
* @return {object} The image data if found in the Cache, otherwise `null`.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
getImage: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._images[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._images[key].data;
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getImage: Invalid key: "' + key + '"');
|
2014-09-03 10:11:48 +00:00
|
|
|
return null;
|
2013-12-10 12:23:42 +00:00
|
|
|
}
|
2013-11-13 20:57:09 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
|
|
|
* Get tilemap data by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2014-06-24 12:16:38 +00:00
|
|
|
* @method Phaser.Cache#getTilemapData
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the tilemap data to retrieve from the Cache.
|
|
|
|
* @return {Object} The raw tilemap data in CSV or JSON format.
|
2013-09-12 03:24:01 +00:00
|
|
|
*/
|
2013-10-11 17:18:27 +00:00
|
|
|
getTilemapData: function (key) {
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
if (this._tilemaps[key])
|
|
|
|
{
|
|
|
|
return this._tilemaps[key];
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getTilemapData: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get frame data by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getFrameData
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
2014-10-01 02:10:13 +00:00
|
|
|
* @param {string} [map=Phaser.Cache.IMAGE] - The asset map to get the frameData from, for example `Phaser.Cache.IMAGE`.
|
2013-12-20 18:27:36 +00:00
|
|
|
* @return {Phaser.FrameData} The frame data.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-10-01 02:10:13 +00:00
|
|
|
getFrameData: function (key, map) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2014-10-01 02:10:13 +00:00
|
|
|
if (typeof map === 'undefined') { map = Phaser.Cache.IMAGE; }
|
|
|
|
|
|
|
|
if (this._cacheMap[map][key])
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2014-10-01 02:10:13 +00:00
|
|
|
return this._cacheMap[map][key].frameData;
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* Replaces a set of frameData with a new Phaser.FrameData object.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#updateFrameData
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {number} frameData - The new FrameData.
|
|
|
|
*/
|
|
|
|
updateFrameData: function (key, frameData) {
|
|
|
|
|
|
|
|
if (this._images[key])
|
|
|
|
{
|
|
|
|
this._images[key].frameData = frameData;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-11 16:32:53 +00:00
|
|
|
/**
|
|
|
|
* Get a single frame out of a frameData set by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getFrameByIndex
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Frame} The frame object.
|
2013-09-11 16:32:53 +00:00
|
|
|
*/
|
|
|
|
getFrameByIndex: function (key, frame) {
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
if (this._images[key])
|
2013-09-11 16:32:53 +00:00
|
|
|
{
|
|
|
|
return this._images[key].frameData.getFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a single frame out of a frameData set by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getFrameByName
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Frame} The frame object.
|
2013-09-11 16:32:53 +00:00
|
|
|
*/
|
|
|
|
getFrameByName: function (key, frame) {
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
if (this._images[key])
|
2013-09-11 16:32:53 +00:00
|
|
|
{
|
|
|
|
return this._images[key].frameData.getFrameByName(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-03 16:07:05 +00:00
|
|
|
/**
|
|
|
|
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getFrame
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Frame} The frame data.
|
2013-09-03 16:07:05 +00:00
|
|
|
*/
|
|
|
|
getFrame: function (key) {
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
if (this._images[key])
|
2013-09-03 16:07:05 +00:00
|
|
|
{
|
|
|
|
return this._images[key].frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
/**
|
2013-12-20 18:27:36 +00:00
|
|
|
* Get a single texture frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getTextureFrame
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the frame to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Frame} The frame data.
|
2013-09-11 01:57:36 +00:00
|
|
|
*/
|
|
|
|
getTextureFrame: function (key) {
|
|
|
|
|
|
|
|
if (this._textures[key])
|
|
|
|
{
|
|
|
|
return this._textures[key].frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a RenderTexture by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getTexture
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the RenderTexture to retrieve from the Cache.
|
|
|
|
* @return {Phaser.RenderTexture} The RenderTexture object.
|
2013-09-11 01:57:36 +00:00
|
|
|
*/
|
|
|
|
getTexture: function (key) {
|
|
|
|
|
|
|
|
if (this._textures[key])
|
|
|
|
{
|
|
|
|
return this._textures[key];
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get sound by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getSound
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the sound to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Sound} The sound object.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
getSound: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._sounds[key];
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getSound: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get sound data by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getSoundData
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the sound to retrieve from the Cache.
|
|
|
|
* @return {object} The sound data.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
getSoundData: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._sounds[key].data;
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getSoundData: Invalid key: "' + key + '"');
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Check if the given sound has finished decoding.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#isSoundDecoded
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the sound in the Cache.
|
2013-11-25 04:40:04 +00:00
|
|
|
* @return {boolean} The decoded state of the Sound object.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
isSoundDecoded: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._sounds[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._sounds[key].decoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#isSoundReady
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the sound in the Cache.
|
2013-11-25 04:40:04 +00:00
|
|
|
* @return {boolean} True if the sound is decoded and the device is not touch locked.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
isSoundReady: function (key) {
|
2013-09-10 15:46:39 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false);
|
2013-09-10 15:46:39 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2014-07-22 08:24:53 +00:00
|
|
|
* Get the number of frames in this image.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2014-07-22 08:24:53 +00:00
|
|
|
* @method Phaser.Cache#getFrameCount
|
|
|
|
* @param {string} key - Asset key of the image you want.
|
2014-10-21 22:08:16 +00:00
|
|
|
* @return {number} Then number of frames. 0 if the image is not found.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2014-07-22 08:24:53 +00:00
|
|
|
getFrameCount: function (key) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._images[key])
|
|
|
|
{
|
2014-07-22 08:42:47 +00:00
|
|
|
return this._images[key].frameData.total;
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 08:24:53 +00:00
|
|
|
return 0;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Get text data by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getText
|
2013-12-20 18:27:36 +00:00
|
|
|
* @param {string} key - Asset key of the text data to retrieve from the Cache.
|
|
|
|
* @return {object} The text data.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
getText: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._text[key])
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._text[key].data;
|
|
|
|
}
|
2013-12-10 12:23:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getText: Invalid key: "' + key + '"');
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
|
|
|
* Get a JSON object by key from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getJSON
|
|
|
|
* @param {string} key - Asset key of the json object to retrieve from the Cache.
|
|
|
|
* @return {object} The JSON object.
|
|
|
|
*/
|
|
|
|
getJSON: function (key) {
|
|
|
|
|
|
|
|
if (this._json[key])
|
|
|
|
{
|
|
|
|
return this._json[key].data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getJSON: Invalid key: "' + key + '"');
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* Get a XML object by key from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getXML
|
|
|
|
* @param {string} key - Asset key of the XML object to retrieve from the Cache.
|
|
|
|
* @return {object} The XML object.
|
|
|
|
*/
|
|
|
|
getXML: function (key) {
|
|
|
|
|
|
|
|
if (this._xml[key])
|
|
|
|
{
|
|
|
|
return this._xml[key].data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getXML: Invalid key: "' + key + '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-12-20 18:27:36 +00:00
|
|
|
/**
|
|
|
|
* Get binary data by key.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getBinary
|
|
|
|
* @param {string} key - Asset key of the binary data object to retrieve from the Cache.
|
|
|
|
* @return {object} The binary data object.
|
|
|
|
*/
|
|
|
|
getBinary: function (key) {
|
|
|
|
|
|
|
|
if (this._binary[key])
|
|
|
|
{
|
|
|
|
return this._binary[key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getBinary: Invalid key: "' + key + '"');
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-12-20 18:27:36 +00:00
|
|
|
},
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
/**
|
|
|
|
* Get a cached object by the URL.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getUrl
|
|
|
|
* @param {string} url - The url for the object loaded to get from the cache.
|
|
|
|
* @return {object} The cached object.
|
|
|
|
*/
|
|
|
|
getUrl: function (url) {
|
|
|
|
|
|
|
|
if (this._urlMap[this._resolveUrl(url)])
|
|
|
|
{
|
|
|
|
return this._urlMap[this._resolveUrl(url)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getUrl: Invalid url: "' + url + '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2014-02-14 23:51:49 +00:00
|
|
|
* Gets all keys used by the Cache for the given data type.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getKeys
|
2014-02-14 23:51:49 +00:00
|
|
|
* @param {number} [type=Phaser.Cache.IMAGE] - The type of Cache keys you wish to get. Can be Cache.CANVAS, Cache.IMAGE, Cache.SOUND, etc.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @return {Array} The array of item keys.
|
|
|
|
*/
|
2014-02-14 23:51:49 +00:00
|
|
|
getKeys: function (type) {
|
|
|
|
|
|
|
|
var array = null;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Phaser.Cache.CANVAS:
|
|
|
|
array = this._canvases;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.IMAGE:
|
|
|
|
array = this._images;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.TEXTURE:
|
|
|
|
array = this._textures;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.SOUND:
|
|
|
|
array = this._sounds;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.TEXT:
|
|
|
|
array = this._text;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.PHYSICS:
|
|
|
|
array = this._physics;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.TILEMAP:
|
|
|
|
array = this._tilemaps;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.BINARY:
|
|
|
|
array = this._binary;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.BITMAPDATA:
|
|
|
|
array = this._bitmapDatas;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Phaser.Cache.BITMAPFONT:
|
|
|
|
array = this._bitmapFont;
|
|
|
|
break;
|
2014-02-21 18:48:06 +00:00
|
|
|
|
|
|
|
case Phaser.Cache.JSON:
|
|
|
|
array = this._json;
|
|
|
|
break;
|
2014-09-18 23:22:00 +00:00
|
|
|
|
|
|
|
case Phaser.Cache.XML:
|
|
|
|
array = this._xml;
|
|
|
|
break;
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
var output = [];
|
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
for (var item in array)
|
|
|
|
{
|
2013-12-03 02:13:57 +00:00
|
|
|
if (item !== '__default' && item !== '__missing')
|
2013-09-10 11:46:14 +00:00
|
|
|
{
|
|
|
|
output.push(item);
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Removes a canvas from the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2013-11-25 04:40:04 +00:00
|
|
|
* @method Phaser.Cache#removeCanvas
|
2013-10-02 14:05:55 +00:00
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeCanvas: function (key) {
|
|
|
|
delete this._canvases[key];
|
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2014-09-16 11:20:03 +00:00
|
|
|
* Removes an image from the cache and optionally from the Pixi.BaseTextureCache as well.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeImage
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
2014-09-16 11:20:03 +00:00
|
|
|
* @param {boolean} [removeFromPixi=true] - Should this image also be removed from the Pixi BaseTextureCache?
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2014-09-16 11:20:03 +00:00
|
|
|
removeImage: function (key, removeFromPixi) {
|
|
|
|
|
|
|
|
if (typeof removeFromPixi === 'undefined') { removeFromPixi = true; }
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
delete this._images[key];
|
2014-09-16 11:20:03 +00:00
|
|
|
|
|
|
|
if (removeFromPixi)
|
|
|
|
{
|
|
|
|
PIXI.BaseTextureCache[key].destroy();
|
|
|
|
}
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
|
|
|
* Removes a sound from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeSound
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeSound: function (key) {
|
|
|
|
delete this._sounds[key];
|
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
|
|
|
* Removes a text from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeText
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeText: function (key) {
|
|
|
|
delete this._text[key];
|
|
|
|
},
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
|
|
|
* Removes a json object from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeJSON
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeJSON: function (key) {
|
|
|
|
delete this._json[key];
|
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
|
|
|
* Removes a xml object from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeXML
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeXML: function (key) {
|
|
|
|
delete this._xml[key];
|
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* Removes a physics data file from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removePhysics
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removePhysics: function (key) {
|
2014-03-10 15:53:08 +00:00
|
|
|
delete this._physics[key];
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a tilemap from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeTilemap
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeTilemap: function (key) {
|
2014-03-10 15:53:08 +00:00
|
|
|
delete this._tilemaps[key];
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a binary file from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeBinary
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBinary: function (key) {
|
2014-03-10 15:53:08 +00:00
|
|
|
delete this._binary[key];
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a bitmap data from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeBitmapData
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBitmapData: function (key) {
|
2014-03-10 15:53:08 +00:00
|
|
|
delete this._bitmapDatas[key];
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a bitmap font from the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#removeBitmapFont
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBitmapFont: function (key) {
|
2014-03-10 15:53:08 +00:00
|
|
|
delete this._bitmapFont[key];
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
/**
|
2014-10-15 20:36:44 +00:00
|
|
|
* Resolves a URL to its absolute form.
|
2014-10-05 02:20:28 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#_resolveUrl
|
2014-10-15 20:36:44 +00:00
|
|
|
* @param {string} url - The URL to resolve.
|
|
|
|
* @return {string} The resolved URL.
|
2014-10-05 02:20:28 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_resolveUrl: function (url) {
|
2014-10-15 20:36:44 +00:00
|
|
|
|
|
|
|
this._urlResolver.src = this.game.load.baseURL + url;
|
2014-10-05 02:20:28 +00:00
|
|
|
|
|
|
|
this._urlTemp = this._urlResolver.src;
|
|
|
|
|
2014-10-15 20:36:44 +00:00
|
|
|
// Ensure no request is actually made
|
2014-10-05 02:20:28 +00:00
|
|
|
this._urlResolver.src = '';
|
|
|
|
|
|
|
|
return this._urlTemp;
|
2014-10-15 20:36:44 +00:00
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Clears the cache. Removes every local cache object reference.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2013-11-25 04:40:04 +00:00
|
|
|
* @method Phaser.Cache#destroy
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
destroy: function () {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._canvases)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._canvases[item];
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._images)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
if (item !== '__default' && item !== '__missing')
|
|
|
|
{
|
|
|
|
delete this._images[item];
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._sounds)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._sounds[item];
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._text)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._text[item];
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
2014-02-14 23:51:49 +00:00
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
for (var item in this._json)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._json[item];
|
2014-02-21 18:48:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
for (var item in this._xml)
|
|
|
|
{
|
|
|
|
delete this._xml[item];
|
|
|
|
}
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
for (var item in this._textures)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._textures[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var item in this._physics)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._physics[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var item in this._tilemaps)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._tilemaps[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var item in this._binary)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._binary[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var item in this._bitmapDatas)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._bitmapDatas[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var item in this._bitmapFont)
|
|
|
|
{
|
2014-03-10 15:22:06 +00:00
|
|
|
delete this._bitmapFont[item];
|
2014-02-14 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
2014-10-05 15:18:52 +00:00
|
|
|
this._urlMap = null;
|
|
|
|
this._urlResolver = null;
|
|
|
|
this._urlTemp = null;
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2013-12-30 16:54:00 +00:00
|
|
|
|
|
|
|
Phaser.Cache.prototype.constructor = Phaser.Cache;
|