2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2015-02-25 03:36:23 +00:00
|
|
|
* @copyright 2015 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Phaser has one single cache in which it stores all assets.
|
|
|
|
*
|
|
|
|
* The cache is split up into sections, such as images, sounds, video, json, etc. All assets are stored using
|
|
|
|
* a unique string-based key as their identifier. Assets stored in different areas of the cache can have the
|
|
|
|
* same key, for example 'playerWalking' could be used as the key for both a sprite sheet and an audio file,
|
|
|
|
* because they are unique data types.
|
|
|
|
*
|
|
|
|
* The cache is automatically populated by the Phaser.Loader. When you use the loader to pull in external assets
|
|
|
|
* such as images they are automatically placed into their respective cache. Most common Game Objects, such as
|
2015-07-15 23:45:56 +00:00
|
|
|
* Sprites and Videos automatically query the cache to extract the assets they need on instantiation.
|
2015-07-15 20:52:19 +00:00
|
|
|
*
|
|
|
|
* You can access the cache from within a State via `this.cache`. From here you can call any public method it has,
|
|
|
|
* including adding new entries to it, deleting them or querying them.
|
|
|
|
*
|
|
|
|
* Understand that almost without exception when you get an item from the cache it will return a reference to the
|
|
|
|
* item stored in the cache, not a copy of it. Therefore if you retrieve an item and then modify it, the original
|
|
|
|
* object in the cache will also be updated, even if you don't put it back into the cache again.
|
|
|
|
*
|
|
|
|
* By default when you change State the cache is _not_ cleared, although there is an option to clear it should
|
|
|
|
* your game require it. In a typical game set-up the cache is populated once after the main game has loaded and
|
|
|
|
* then used as an asset store.
|
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-10-27 11:43:44 +00:00
|
|
|
/**
|
2015-07-15 14:00:21 +00:00
|
|
|
* Automatically resolve resource URLs to absolute paths for use with the Cache.getURL method.
|
|
|
|
* @property {boolean} autoResolveURL
|
2014-10-27 11:43:44 +00:00
|
|
|
*/
|
|
|
|
this.autoResolveURL = false;
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 14:00:21 +00:00
|
|
|
* The main cache object into which all resources are placed.
|
|
|
|
* @property {object} _cache
|
2013-11-25 04:40:04 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-07-15 14:00:21 +00:00
|
|
|
this._cache = {
|
|
|
|
canvas: {},
|
|
|
|
image: {},
|
|
|
|
texture: {},
|
|
|
|
sound: {},
|
|
|
|
video: {},
|
|
|
|
text: {},
|
|
|
|
json: {},
|
|
|
|
xml: {},
|
|
|
|
physics: {},
|
|
|
|
tilemap: {},
|
|
|
|
binary: {},
|
|
|
|
bitmapData: {},
|
|
|
|
bitmapFont: {
|
|
|
|
image: {},
|
|
|
|
data: {}
|
|
|
|
},
|
|
|
|
shader: {},
|
2015-07-15 23:45:56 +00:00
|
|
|
renderTexture: {}
|
2015-07-15 14:00:21 +00:00
|
|
|
};
|
2014-02-14 16:38:06 +00:00
|
|
|
|
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-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.
|
2015-03-23 08:13:26 +00:00
|
|
|
* @private
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
this._cacheMap = [];
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
this._cacheMap[Phaser.Cache.CANVAS] = this._cache.canvas;
|
|
|
|
this._cacheMap[Phaser.Cache.IMAGE] = this._cache.image;
|
|
|
|
this._cacheMap[Phaser.Cache.TEXTURE] = this._cache.texture;
|
|
|
|
this._cacheMap[Phaser.Cache.SOUND] = this._cache.sound;
|
|
|
|
this._cacheMap[Phaser.Cache.TEXT] = this._cache.text;
|
|
|
|
this._cacheMap[Phaser.Cache.PHYSICS] = this._cache.physics;
|
|
|
|
this._cacheMap[Phaser.Cache.TILEMAP] = this._cache.tilemap;
|
|
|
|
this._cacheMap[Phaser.Cache.BINARY] = this._cache.binary;
|
|
|
|
this._cacheMap[Phaser.Cache.BITMAPDATA] = this._cache.bitmapData;
|
|
|
|
this._cacheMap[Phaser.Cache.BITMAPFONT] = this._cache.bitmapFont;
|
|
|
|
this._cacheMap[Phaser.Cache.JSON] = this._cache.json;
|
|
|
|
this._cacheMap[Phaser.Cache.XML] = this._cache.xml;
|
|
|
|
this._cacheMap[Phaser.Cache.VIDEO] = this._cache.video;
|
|
|
|
this._cacheMap[Phaser.Cache.SHADER] = this._cache.shader;
|
|
|
|
this._cacheMap[Phaser.Cache.RENDER_TEXTURE] = this._cache.renderTexture;
|
2014-05-19 10:34:14 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
this.addDefaultImage();
|
|
|
|
this.addMissingImage();
|
|
|
|
|
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;
|
|
|
|
|
2015-05-03 12:42:41 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.VIDEO = 13;
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.SHADER = 14;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
Phaser.Cache.RENDER_TEXTURE = 15;
|
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
Phaser.Cache.prototype = {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
//////////////////
|
|
|
|
// Add Methods //
|
|
|
|
//////////////////
|
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {HTMLCanvasElement} canvas - The Canvas DOM element.
|
|
|
|
* @param {CanvasRenderingContext2D} [context] - The context of the canvas element. If not specified it will default go `getContext('2d')`.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
addCanvas: function (key, canvas, context) {
|
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (context === undefined) { context = canvas.getContext('2d'); }
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
this._cache.canvas[key] = { canvas: canvas, context: context };
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-12-20 18:27:36 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM.
|
|
|
|
* If an image already exists in the cache with the same key then it is removed and destroyed, and the new image inserted in its place.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addImage
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra image data.
|
2013-12-20 18:27:36 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addImage: function (key, url, data) {
|
2013-12-20 18:27:36 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (this.checkImageKey(key))
|
|
|
|
{
|
|
|
|
this.removeImage(key);
|
|
|
|
}
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var img = {
|
2015-07-15 23:45:56 +00:00
|
|
|
key: key,
|
2015-07-15 16:06:29 +00:00
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
base: new PIXI.BaseTexture(data),
|
|
|
|
frame: new Phaser.Frame(0, 0, 0, data.width, data.height, key),
|
|
|
|
frameData: new Phaser.FrameData()
|
|
|
|
};
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 22:22:51 +00:00
|
|
|
img.frameData.addFrame(new Phaser.Frame(0, 0, 0, data.width, data.height, url));
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._cache.image[key] = img;
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._resolveURL(url, img);
|
2013-12-20 18:27:36 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-13 20:57:09 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Adds a default image to be used in special cases such as WebGL Filters.
|
|
|
|
* It uses the special reserved key of `__default`.
|
|
|
|
* This method is called automatically when the Cache is created.
|
|
|
|
* This image is skipped when `Cache.destroy` is called due to its internal requirements.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addDefaultImage
|
|
|
|
* @protected
|
2013-11-13 20:57:09 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addDefaultImage: function () {
|
2013-11-13 20:57:09 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
var img = new Image();
|
2014-10-01 02:10:13 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==";
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this.addImage('__default', null, img);
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Adds an image to be used when a key is wrong / missing.
|
|
|
|
* It uses the special reserved key of `__missing`.
|
|
|
|
* This method is called automatically when the Cache is created.
|
|
|
|
* This image is skipped when `Cache.destroy` is called due to its internal requirements.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addMissingImage
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
addMissingImage: function () {
|
|
|
|
|
|
|
|
var img = new Image();
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this.addImage('__missing', null, img);
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Sound file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addSound
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
addSound: function (key, url, data, webAudio, audioTag) {
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
if (webAudio === undefined) { webAudio = true; audioTag = false; }
|
|
|
|
if (audioTag === undefined) { webAudio = false; audioTag = true; }
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
var decoded = false;
|
|
|
|
|
|
|
|
if (audioTag)
|
2014-11-07 08:08:54 +00:00
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
decoded = true;
|
2014-11-07 08:08:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._cache.sounds[key] = {
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
isDecoding: false,
|
|
|
|
decoded: decoded,
|
|
|
|
webAudio: webAudio,
|
|
|
|
audioTag: audioTag,
|
|
|
|
locked: this.game.sound.touchLocked
|
|
|
|
};
|
2013-11-13 20:57:09 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.sounds[key]);
|
2013-11-13 20:57:09 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new text data.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addText
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra text data.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addText: function (key, url, data) {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.text[key] = { url: url, data: data };
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.text[key]);
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new physics data object to the Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addPhysicsData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} JSONData - The physics data object (a JSON file).
|
|
|
|
* @param {number} format - The format of the physics data.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addPhysicsData: function (key, url, JSONData, format) {
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.physics[key] = { url: url, data: JSONData, format: format };
|
2013-08-30 01:18:00 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.physics[key]);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
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
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
this._cache.tilemap[key] = { url: url, data: mapData, format: format };
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
this._resolveURL(url, this._cache.tilemap[key]);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a binary object in to the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addBinary
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {object} binaryData - The binary object to be added to the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addBinary: function (key, binaryData) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.binary[key] = binaryData;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
},
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
/**
|
|
|
|
* Add a BitmapData object to the cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#addBitmapData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
|
|
|
|
* @param {Phaser.FrameData|null} [frameData=(auto create)] - Optional FrameData set associated with the given BitmapData. If not specified (or `undefined`) a new FrameData object is created containing the Bitmap's Frame. If `null` is supplied then no FrameData will be created.
|
|
|
|
* @return {Phaser.BitmapData} The BitmapData object to be addded to the cache.
|
|
|
|
*/
|
|
|
|
addBitmapData: function (key, bitmapData, frameData) {
|
|
|
|
|
|
|
|
bitmapData.key = key;
|
|
|
|
|
|
|
|
if (typeof frameData === 'undefined')
|
2013-08-28 06:02:55 +00:00
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
frameData = new Phaser.FrameData();
|
|
|
|
frameData.addFrame(bitmapData.textureFrame);
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.bitmapData[key] = { data: bitmapData, frameData: frameData };
|
|
|
|
|
|
|
|
return bitmapData;
|
2014-10-05 02:20:28 +00:00
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @param {object} data - Extra font data.
|
2015-06-06 10:35:08 +00:00
|
|
|
* @param {object} atlasData - Texture atlas frames data.
|
2014-02-14 04:34:57 +00:00
|
|
|
* @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
|
|
|
*/
|
2015-06-06 10:35:08 +00:00
|
|
|
addBitmapFont: function (key, url, data, atlasData, atlasType, xSpacing, ySpacing) {
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var obj = {
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
font: null,
|
|
|
|
base: new PIXI.BaseTexture(data)
|
|
|
|
};
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-06-06 10:35:08 +00:00
|
|
|
if (atlasType === 'json')
|
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
// TODO: These can return the object rather than add it to the PIXI Cache
|
2015-06-06 10:35:08 +00:00
|
|
|
Phaser.LoaderParser.jsonBitmapFont(this.game, atlasData, key, xSpacing, ySpacing);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Phaser.LoaderParser.xmlBitmapFont(this.game, atlasData, key, xSpacing, ySpacing);
|
|
|
|
}
|
2013-09-10 22:51:35 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
obj.font = PIXI.BitmapText.fonts[key];;
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._cache.bitmapFont[key] = obj;
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._resolveURL(url, obj);
|
2014-08-28 02:52:26 +00:00
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new json object into the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addJSON
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra json data.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addJSON: function (key, url, data) {
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.json[key] = { url: url, data: data };
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.json[key]);
|
2013-09-10 10:09:25 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-21 04:59:54 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new xml object into the cache.
|
2013-11-21 04:59:54 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addXML
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra text data.
|
2013-11-21 04:59:54 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addXML: function (key, url, data) {
|
2013-11-21 04:59:54 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.xml[key] = { url: url, data: data };
|
2013-11-21 04:59:54 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.xml[key]);
|
2013-11-21 04:59:54 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Adds a Video file into the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
2013-10-11 03:42:11 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addVideo
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra video data.
|
|
|
|
* @param {boolean} isBlob - True if the file was preloaded via xhr and the data parameter is a Blob. false if a Video tag was created instead.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addVideo: function (key, url, data, isBlob) {
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.video[key] = { url: url, data: data, isBlob: isBlob, locked: true };
|
2013-10-11 03:42:11 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.video[key]);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2013-10-11 03:42:11 +00:00
|
|
|
},
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Adds a Fragment Shader in to the Cache. The file must have already been loaded, typically via Phaser.Loader.
|
2014-02-21 18:48:06 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addShader
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra shader data.
|
2014-02-21 18:48:06 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addShader: function (key, url, data) {
|
2014-02-21 18:48:06 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.shader[key] = { url: url, data: data };
|
2014-02-21 18:48:06 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._resolveURL(url, this._cache.shader[key]);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new Phaser.RenderTexture in to the cache.
|
2014-09-18 23:22:00 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addRenderTexture
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {Phaser.RenderTexture} texture - The texture to use as the base of the RenderTexture.
|
2014-09-18 23:22:00 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addRenderTexture: function (key, texture) {
|
2014-09-18 23:22:00 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
this._cache.renderTexture[key] = { texture: texture, frame: new Phaser.Frame(0, 0, 0, texture.width, texture.height, '', '') };
|
2014-10-27 11:43:44 +00:00
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new sprite sheet in to the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addSpriteSheet
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra sprite sheet data.
|
|
|
|
* @param {number} frameWidth - Width of the sprite sheet.
|
|
|
|
* @param {number} frameHeight - Height of the sprite sheet.
|
|
|
|
* @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
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax, margin, spacing) {
|
2013-10-24 20:21:00 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var obj = {
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
frameWidth: frameWidth,
|
|
|
|
frameHeight: frameHeight,
|
|
|
|
margin: margin,
|
|
|
|
spacing: spacing,
|
|
|
|
base: new PIXI.BaseTexture(data),
|
2015-07-16 00:02:59 +00:00
|
|
|
frameData: Phaser.AnimationParser.spriteSheet(this.game, data, frameWidth, frameHeight, frameMax, margin, spacing)
|
2015-07-15 16:06:29 +00:00
|
|
|
};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 23:45:56 +00:00
|
|
|
this._cache.image[key] = obj;
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
this._resolveURL(url, obj);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Add a new texture atlas to the Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#addTextureAtlas
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache.
|
|
|
|
* @param {string} url - The URL the asset was loaded from. If the asset was not loaded externally set to `null`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {object} data - Extra texture atlas data.
|
|
|
|
* @param {object} atlasData - Texture atlas frames data.
|
|
|
|
* @param {number} format - The format of the texture atlas.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
addTextureAtlas: function (key, url, data, atlasData, format) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 23:45:56 +00:00
|
|
|
var obj = {
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
base: new PIXI.BaseTexture(data)
|
|
|
|
};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 23:45:56 +00:00
|
|
|
if (format === Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
obj.frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
|
2015-07-15 15:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Let's just work it out from the frames array
|
|
|
|
if (Array.isArray(atlasData.frames))
|
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
obj.frameData = Phaser.AnimationParser.JSONData(this.game, atlasData, key);
|
2015-07-15 15:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
obj.frameData = Phaser.AnimationParser.JSONDataHash(this.game, atlasData, key);
|
2015-07-15 15:33:01 +00:00
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-15 23:45:56 +00:00
|
|
|
this._cache.image[key] = obj;
|
2015-07-15 16:06:29 +00:00
|
|
|
|
|
|
|
this._resolveURL(url, obj);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
////////////////////////////
|
|
|
|
// Sound Related Methods //
|
|
|
|
////////////////////////////
|
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
reloadSound: function (key) {
|
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var sound = this.getSound(key);
|
|
|
|
|
|
|
|
if (sound)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
sound.data.src = sound.url;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
sound.data.addEventListener('canplaythrough', function () {
|
2013-08-28 06:02:55 +00:00
|
|
|
return _this.reloadSoundComplete(key);
|
|
|
|
}, false);
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
sound.data.load();
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
2015-07-15 16:06:29 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
reloadSoundComplete: function (key) {
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var sound = this.getSound(key);
|
|
|
|
|
|
|
|
if (sound)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
sound.locked = false;
|
2013-08-28 06:02:55 +00:00
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
updateSound: function (key, property, value) {
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var sound = this.getSound(key);
|
|
|
|
|
|
|
|
if (sound)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2015-07-15 16:06:29 +00:00
|
|
|
sound[property] = value;
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2013-11-25 04:40:04 +00:00
|
|
|
* @param {object} data - Extra sound data.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
decodedSound: function (key, data) {
|
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
var sound = this.getSound(key);
|
|
|
|
|
|
|
|
sound.data = data;
|
|
|
|
sound.decoded = true;
|
|
|
|
sound.isDecoding = false;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Check if the given sound has finished decoding.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#isSoundDecoded
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {boolean} The decoded state of the Sound object.
|
2014-02-14 23:51:49 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
isSoundDecoded: function (key) {
|
2014-04-01 00:30:20 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
var sound = this.getItem(key, Phaser.Cache.SOUND, 'isSoundDecoded');
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (sound)
|
|
|
|
{
|
|
|
|
return sound.decoded;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +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.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#isSoundReady
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {boolean} True if the sound is decoded and the device is not touch locked.
|
|
|
|
*/
|
|
|
|
isSoundReady: function (key) {
|
|
|
|
|
|
|
|
var sound = this.getItem(key, Phaser.Cache.SOUND, 'isSoundDecoded');
|
|
|
|
|
|
|
|
if (sound)
|
|
|
|
{
|
|
|
|
return (sound.decoded && !this.game.sound.touchLocked);
|
|
|
|
}
|
2014-02-14 23:51:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
////////////////////////
|
|
|
|
// Check Key Methods //
|
|
|
|
////////////////////////
|
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {integer} cache - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
|
|
|
* @param {string} key - The key of the asset within 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
|
|
|
*/
|
2015-07-15 16:06:29 +00:00
|
|
|
checkKey: function (cache, key) {
|
2013-09-10 10:09:25 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
if (this._cacheMap[cache][key])
|
2013-09-10 10:09:25 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given URL has been loaded into the Cache.
|
|
|
|
* This method will only work if Cache.autoResolveURL was set to `true` before any preloading took place.
|
|
|
|
* The method will make a DOM src call to the URL given, so please be aware of this for certain file types, such as Sound files on Firefox
|
|
|
|
* which may cause double-load instances.
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-05-19 10:34:14 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Canvas Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkCanvasKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkImageKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.IMAGE, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Texture Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTextureKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkTextureKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TEXTURE, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Sound Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkSoundKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkSoundKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.SOUND, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Text Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTextKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkTextKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TEXT, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Physics Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkPhysicsKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkPhysicsKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.PHYSICS, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Tilemap Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkTilemapKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkTilemapKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.TILEMAP, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Binary Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBinaryKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkBinaryKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BINARY, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the BitmapData Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBitmapDataKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkBitmapDataKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BITMAPDATA, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the BitmapFont Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkBitmapFontKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
checkBitmapFontKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.BITMAPFONT, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the JSON Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkJSONKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-05-19 10:34:14 +00:00
|
|
|
*/
|
|
|
|
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
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2014-09-18 23:22:00 +00:00
|
|
|
*/
|
|
|
|
checkXMLKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.XML, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Video Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkVideoKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2015-07-15 14:00:21 +00:00
|
|
|
*/
|
|
|
|
checkVideoKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.VIDEO, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Fragment Shader Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkShaderKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2015-07-15 14:00:21 +00:00
|
|
|
*/
|
|
|
|
checkShaderKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.SHADER, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given key exists in the Render Texture Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#checkRenderTextureKey
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
|
|
|
* @return {boolean} True if the key exists in the cache, otherwise false.
|
2015-07-15 14:00:21 +00:00
|
|
|
*/
|
|
|
|
checkRenderTextureKey: function (key) {
|
|
|
|
|
|
|
|
return this.checkKey(Phaser.Cache.RENDER_TEXTURE, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
////////////////
|
|
|
|
// Get Items //
|
|
|
|
////////////////
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2015-05-03 12:42:41 +00:00
|
|
|
/**
|
2015-07-15 14:00:21 +00:00
|
|
|
* Get an item from a cache based on the given key and property.
|
|
|
|
*
|
|
|
|
* This method is mostly used internally by other Cache methods such as `getImage` but is exposed
|
|
|
|
* publicly for your own use as well.
|
2015-05-03 12:42:41 +00:00
|
|
|
*
|
2015-07-15 14:00:21 +00:00
|
|
|
* @method Phaser.Cache#getItem
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset within the cache.
|
2015-07-15 14:00:21 +00:00
|
|
|
* @param {integer} cache - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
|
|
|
* @param {string} [method] - The string name of the method calling getItem. Can be empty, in which case no console warning is output.
|
|
|
|
* @param {string} [property] - If you require a specific property from the cache item, specify it here.
|
|
|
|
* @return {object} The cached item if found, otherwise `null`. If the key is invalid and `method` is set then a console.warn is output.
|
2015-05-03 12:42:41 +00:00
|
|
|
*/
|
2015-07-15 14:00:21 +00:00
|
|
|
getItem: function (key, cache, method, property) {
|
2015-05-03 12:42:41 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (!this.checkKey(cache, key))
|
2015-05-03 12:42:41 +00:00
|
|
|
{
|
2015-07-15 14:00:21 +00:00
|
|
|
if (method)
|
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
console.warn('Phaser.Cache.' + method + ': Key "' + key + '" not found in Cache.');
|
2015-07-15 14:00:21 +00:00
|
|
|
}
|
2015-05-03 12:42:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-15 14:00:21 +00:00
|
|
|
if (property === undefined)
|
|
|
|
{
|
|
|
|
return this._cacheMap[cache][key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this._cacheMap[cache][key][property];
|
|
|
|
}
|
2015-05-03 12:42:41 +00:00
|
|
|
}
|
2015-07-15 14:00:21 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Canvas object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getCanvas
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {object} The canvas object or `null` if no item could be found matching the given key.
|
|
|
|
*/
|
|
|
|
getCanvas: function (key) {
|
|
|
|
|
|
|
|
return this.getItem(key, Phaser.Cache.CANVAS, 'getCanvas', 'canvas');
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Image object from the cache. This returns a DOM Image object, not a Phaser.Image object.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
|
|
|
*
|
2015-07-15 23:45:56 +00:00
|
|
|
* Only the Image cache is searched, which covers images loaded via Loader.image, Sprite Sheets and Texture Atlases.
|
2015-07-15 20:52:19 +00:00
|
|
|
*
|
2015-07-15 23:45:56 +00:00
|
|
|
* If you need the image used by a bitmap font or similar then please use those respective 'get' methods.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getImage
|
2015-07-15 23:45:56 +00:00
|
|
|
* @param {string} [key] - The key of the asset to retrieve from the cache. If not given or null it will return a default image. If given but not found in the cache it will throw a warning and return the missing image.
|
|
|
|
* @param {boolean} [full=false] - If true the full image object will be returned, if false just the HTML Image object is returned.
|
|
|
|
* @return {Image} The Image object if found in the Cache, otherwise `null`. If `full` was true then a JavaScript object is returned.
|
2015-07-15 15:33:01 +00:00
|
|
|
*/
|
2015-07-15 23:45:56 +00:00
|
|
|
getImage: function (key, full) {
|
|
|
|
|
|
|
|
if (key === undefined || key === null)
|
|
|
|
{
|
|
|
|
key = '__default';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (full === undefined) { full = false; }
|
|
|
|
|
|
|
|
var img = this.getItem(key, Phaser.Cache.IMAGE, 'getImage');
|
|
|
|
|
|
|
|
if (img === null)
|
|
|
|
{
|
|
|
|
img = this.getItem('__missing', Phaser.Cache.IMAGE, 'getImage');
|
|
|
|
}
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 23:45:56 +00:00
|
|
|
if (full)
|
|
|
|
{
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return img.data;
|
|
|
|
}
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a single texture frame by key.
|
2015-07-15 20:52:19 +00:00
|
|
|
*
|
|
|
|
* You'd only do this to get the default Frame created for a non-atlas / spritesheet image.
|
2015-07-15 14:00:21 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getTextureFrame
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.Frame} The frame data.
|
2015-07-15 14:00:21 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getTextureFrame: function (key) {
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.TEXTURE, 'getTextureFrame', 'frame');
|
2015-05-03 12:42:41 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Phaser.Sound object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-05-03 12:42:41 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getSound
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.Sound} The sound object.
|
2015-05-03 12:42:41 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getSound: function (key) {
|
2015-05-03 12:42:41 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.SOUND, 'getSound');
|
2015-05-03 12:42:41 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a raw Sound data object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-05-03 12:42:41 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getSoundData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {object} The sound data.
|
2015-05-03 12:42:41 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getSoundData: function (key) {
|
2015-05-03 12:42:41 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.SOUND, 'getSoundData', 'data');
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Text object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getText
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {object} The text data.
|
|
|
|
*/
|
|
|
|
getText: function (key) {
|
|
|
|
|
|
|
|
return this.getItem(key, Phaser.Cache.TEXT, 'getText', 'data');
|
2015-05-03 12:42:41 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Physics Data object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
|
|
|
*
|
2015-07-15 14:00:21 +00:00
|
|
|
* You can get either the entire data set, a single object or a single fixture of an object from it.
|
2015-05-03 12:42:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getPhysicsData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-05-03 12:42:41 +00:00
|
|
|
* @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.
|
|
|
|
* @param {string} fixtureKey - Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter.
|
|
|
|
* @return {object} The requested physics object data if found.
|
|
|
|
*/
|
|
|
|
getPhysicsData: function (key, object, fixtureKey) {
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
var data = this.getItem(key, Phaser.Cache.PHYSICS, 'getPhysicsData', 'data');
|
|
|
|
|
|
|
|
if (data === null || object === undefined || object === null)
|
2015-05-03 12:42:41 +00:00
|
|
|
{
|
2015-07-15 14:00:21 +00:00
|
|
|
return data;
|
2015-05-03 12:42:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-15 14:00:21 +00:00
|
|
|
if (data[object])
|
2015-05-03 12:42:41 +00:00
|
|
|
{
|
2015-07-15 14:00:21 +00:00
|
|
|
var fixtures = data[object];
|
2015-05-03 12:42:41 +00:00
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
// Try to find a fixture by its fixture key if given
|
2015-05-03 12:42:41 +00:00
|
|
|
if (fixtures && fixtureKey)
|
|
|
|
{
|
|
|
|
for (var fixture in fixtures)
|
|
|
|
{
|
|
|
|
// This contains the fixture data of a polygon or a circle
|
|
|
|
fixture = fixtures[fixture];
|
|
|
|
|
|
|
|
// Test the key
|
|
|
|
if (fixture.fixtureKey === fixtureKey)
|
|
|
|
{
|
|
|
|
return fixture;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We did not find the requested fixture
|
|
|
|
console.warn('Phaser.Cache.getPhysicsData: Could not find given fixtureKey: "' + fixtureKey + ' in ' + key + '"');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return fixtures;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getPhysicsData: Invalid key/object: "' + key + ' / ' + object + '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a raw Tilemap data object from the cache. This will be in either CSV or JSON format.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2014-06-24 12:16:38 +00:00
|
|
|
* @method Phaser.Cache#getTilemapData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2014-11-30 11:10:52 +00:00
|
|
|
* @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
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.TILEMAP, 'getTilemapData');
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a binary object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getBinary
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {object} The binary data object.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getBinary: function (key) {
|
2014-10-01 02:10:13 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.BINARY, 'getBinary');
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a BitmapData object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2014-02-14 23:51:49 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getBitmapData
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.BitmapData} The requested BitmapData object if found, or null if not.
|
2014-02-14 23:51:49 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getBitmapData: function (key) {
|
2014-02-14 23:51:49 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.BITMAPDATA, 'getBitmapData', 'data');
|
2014-02-14 23:51:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-11 16:32:53 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Bitmap Font object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getBitmapFont
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.BitmapFont} The requested BitmapFont object if found, or null if not.
|
2013-09-11 16:32:53 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getBitmapFont: function (key) {
|
2013-09-11 16:32:53 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.BITMAPFONT, 'getBitmapFont');
|
2013-09-11 16:32:53 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a JSON object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-07-15 15:33:01 +00:00
|
|
|
*
|
|
|
|
* You can either return the object by reference (the default), or return a clone
|
2015-07-15 20:52:19 +00:00
|
|
|
* of it by setting the `clone` argument to `true`.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getJSON
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @param {boolean} [clone=false] - Return a clone of the original object (true) or a reference to it? (false)
|
|
|
|
* @return {object} The JSON object.
|
2013-09-11 16:32:53 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getJSON: function (key, clone) {
|
2013-09-11 16:32:53 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
var data = this.getItem(key, Phaser.Cache.JSON, 'getJSON', 'data');
|
2015-07-15 14:00:21 +00:00
|
|
|
|
|
|
|
if (data)
|
2013-09-11 16:32:53 +00:00
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
if (clone)
|
|
|
|
{
|
|
|
|
return Phaser.Utils.extend(true, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}
|
2015-07-15 14:00:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
2013-09-11 16:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 16:07:05 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets an XML object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getXML
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {object} The XML object.
|
2013-09-03 16:07:05 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getXML: function (key) {
|
2013-09-03 16:07:05 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.XML, 'getXML', 'data');
|
2015-07-15 14:00:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Phaser.Video object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2015-07-15 14:00:21 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getVideo
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.Video} The video object.
|
2015-07-15 14:00:21 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getVideo: function (key) {
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.VIDEO, 'getVideo');
|
2013-09-03 16:07:05 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a fragment shader object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getShader
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {string} The shader object.
|
2013-09-11 01:57:36 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getShader: function (key) {
|
2013-09-11 01:57:36 +00:00
|
|
|
|
2015-07-15 22:22:51 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.SHADER, 'getShader', 'data');
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a RenderTexture object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2014-10-27 11:43:44 +00:00
|
|
|
* @method Phaser.Cache#getRenderTexture
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - The key of the asset to retrieve from the cache.
|
2014-10-27 11:43:44 +00:00
|
|
|
* @return {Phaser.RenderTexture} The RenderTexture object.
|
|
|
|
*/
|
|
|
|
getRenderTexture: function (key) {
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.RENDER_TEXTURE, 'getRenderTexture');
|
2014-10-27 11:43:44 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
////////////////////////////
|
|
|
|
// Frame Related Methods //
|
|
|
|
////////////////////////////
|
2015-04-13 19:25:42 +00:00
|
|
|
|
2015-07-15 16:06:29 +00:00
|
|
|
/**
|
|
|
|
* Gets a PIXI.BaseTexture by key from the given Cache.
|
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getBaseTexture
|
|
|
|
* @param {string} key - Asset key of the image for which you want the BaseTexture for.
|
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search for the item in.
|
|
|
|
* @return {PIXI.BaseTexture} The BaseTexture object.
|
|
|
|
*/
|
|
|
|
getBaseTexture: function (key, cache) {
|
|
|
|
|
|
|
|
if (cache === undefined) { cache = Phaser.Cache.IMAGE; }
|
|
|
|
|
|
|
|
return this.getItem(key, cache, 'getBaseTexture', 'base');
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-04-13 19:25:42 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +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.
|
2015-04-13 19:25:42 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getFrame
|
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
|
|
|
* @return {Phaser.Frame} The frame data.
|
2015-04-13 19:25:42 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getFrame: function (key) {
|
2015-04-13 19:25:42 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
return this.getItem(key, Phaser.Cache.IMAGE, 'getFrame', 'frame');
|
2013-09-11 01:57:36 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Get the total number of frames contained in the FrameData object specified by the given key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getFrameCount
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} key - Asset key of the FrameData you want.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {number} Then number of frames. 0 if the image is not found.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getFrameCount: function (key) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (map === undefined) { map = Phaser.Cache.IMAGE; }
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
var data = this.getFrameData(key, map);
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
return data.total;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a Phaser.FrameData object from the cache.
|
|
|
|
*
|
|
|
|
* The object is looked-up based on the key given.
|
|
|
|
*
|
|
|
|
* Note: If the object cannot be found a `console.warn` message is displayed.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getFrameData
|
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.FrameData} The frame data.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
getFrameData: function (key, cache) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (cache === undefined) { cache = Phaser.Cache.IMAGE; }
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
return this.getItem(key, cache, 'getFrameData', 'frameData');
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Check if the FrameData for the given key exists in the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#hasFrameData
|
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {boolean} True if the given key has frameData in the cache, otherwise false.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
hasFrameData: function (key, cache) {
|
2013-09-10 15:46:39 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (cache === undefined) { cache = Phaser.Cache.IMAGE; }
|
2015-07-15 14:00:21 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
return (this.getItem(key, cache, '', 'frameData') !== null);
|
2013-09-10 15:46:39 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2015-05-03 12:42:41 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Replaces a set of frameData with a new Phaser.FrameData object.
|
2015-05-03 12:42:41 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#updateFrameData
|
|
|
|
* @param {string} key - The unique key by which you will reference this object.
|
|
|
|
* @param {number} frameData - The new FrameData.
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
2015-05-03 12:42:41 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
updateFrameData: function (key, frameData, cache) {
|
2015-05-03 12:42:41 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (cache === undefined) { cache = Phaser.Cache.IMAGE; }
|
2015-07-15 15:33:01 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (this._cacheMap[cache][key])
|
2015-07-15 15:33:01 +00:00
|
|
|
{
|
2015-07-15 20:52:19 +00:00
|
|
|
this._cacheMap[cache][key].frameData = frameData;
|
2015-07-15 15:33:01 +00:00
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Get a single frame out of a frameData set by key.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getFrameByIndex
|
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {number} index - The index of the frame you want to get.
|
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.Frame} The frame object.
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
getFrameByIndex: function (key, index, cache) {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
var data = this.getFrameData(key, cache);
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
2015-07-15 20:52:19 +00:00
|
|
|
return data.getFrame(index);
|
2015-07-15 15:33:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
/**
|
2015-07-15 15:33:01 +00:00
|
|
|
* Get a single frame out of a frameData set by key.
|
2014-02-21 18:48:06 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getFrameByName
|
|
|
|
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {string} name - The name of the frame you want to get.
|
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`.
|
2015-07-15 15:33:01 +00:00
|
|
|
* @return {Phaser.Frame} The frame object.
|
2014-02-21 18:48:06 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
getFrameByName: function (key, name, cache) {
|
2014-02-21 18:48:06 +00:00
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
var data = this.getFrameData(key, cache);
|
2015-07-15 14:00:21 +00:00
|
|
|
|
|
|
|
if (data)
|
2014-02-21 18:48:06 +00:00
|
|
|
{
|
2015-07-15 20:52:19 +00:00
|
|
|
return data.getFrameByName(name);
|
2014-02-21 18:48:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-09 20:06:02 +00:00
|
|
|
return null;
|
2014-02-21 18:48:06 +00:00
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-02-21 18:48:06 +00:00
|
|
|
},
|
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a PIXI.Texture by key from the PIXI.TextureCache.
|
2014-09-18 23:22:00 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getPixiTexture
|
|
|
|
* @deprecated
|
|
|
|
* @param {string} key - Asset key of the Texture to retrieve from the Cache.
|
|
|
|
* @return {PIXI.Texture} The Texture object.
|
2014-09-18 23:22:00 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getPixiTexture: function (key) {
|
2014-09-18 23:22:00 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (PIXI.TextureCache[key])
|
|
|
|
{
|
|
|
|
return PIXI.TextureCache[key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getPixiTexture: Invalid key: "' + key + '"');
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-18 23:22:00 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-12-20 18:27:36 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Gets a PIXI.BaseTexture by key from the PIXI.BaseTExtureCache.
|
2013-12-20 18:27:36 +00:00
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#getPixiBaseTexture
|
|
|
|
* @deprecated
|
|
|
|
* @param {string} key - Asset key of the BaseTexture to retrieve from the Cache.
|
|
|
|
* @return {PIXI.BaseTexture} The BaseTexture object.
|
2013-12-20 18:27:36 +00:00
|
|
|
*/
|
2015-07-15 15:33:01 +00:00
|
|
|
getPixiBaseTexture: function (key) {
|
2013-12-20 18:27:36 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
if (PIXI.BaseTextureCache[key])
|
|
|
|
{
|
|
|
|
return PIXI.BaseTextureCache[key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
console.warn('Phaser.Cache.getPixiBaseTexture: Invalid key: "' + key + '"');
|
|
|
|
return null;
|
|
|
|
}
|
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.
|
2014-10-27 11:43:44 +00:00
|
|
|
* This only returns a value if you set Cache.autoResolveURL to `true` *before* starting the preload of any assets.
|
|
|
|
* Be aware that every call to this function makes a DOM src query, so use carefully and double-check for implications in your target browsers/devices.
|
2014-10-05 02:20:28 +00:00
|
|
|
*
|
2014-10-27 11:43:44 +00:00
|
|
|
* @method Phaser.Cache#getURL
|
2014-10-05 02:20:28 +00:00
|
|
|
* @param {string} url - The url for the object loaded to get from the cache.
|
|
|
|
* @return {object} The cached object.
|
|
|
|
*/
|
2014-10-27 11:43:44 +00:00
|
|
|
getURL: function (url) {
|
|
|
|
|
|
|
|
var url = this._resolveURL(url);
|
2014-10-05 02:20:28 +00:00
|
|
|
|
2014-10-27 11:43:44 +00:00
|
|
|
if (url)
|
2014-10-05 02:20:28 +00:00
|
|
|
{
|
2014-10-27 11:43:44 +00:00
|
|
|
return this._urlMap[url];
|
2014-10-05 02:20:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-27 11:43:44 +00:00
|
|
|
console.warn('Phaser.Cache.getUrl: Invalid url: "' + url + '" or Cache.autoResolveURL was false');
|
2014-11-09 20:06:02 +00:00
|
|
|
return null;
|
2014-10-05 02:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2015-07-15 14:00:21 +00:00
|
|
|
* Gets all keys used in the requested Cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Cache#getKeys
|
2015-07-15 20:52:19 +00:00
|
|
|
* @param {integer} [cache=Phaser.Cache.IMAGE] - The Cache you wish to get the keys from. Can be any of the Cache consts such as `Phaser.Cache.IMAGE`, `Phaser.Cache.SOUND` etc.
|
2015-07-15 14:00:21 +00:00
|
|
|
* @return {Array} The array of keys in the requested cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
2015-07-15 20:52:19 +00:00
|
|
|
getKeys: function (cache) {
|
|
|
|
|
|
|
|
if (cache === undefined) { cache = Phaser.Cache.IMAGE; }
|
2014-02-14 23:51:49 +00:00
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
var out = [];
|
|
|
|
|
2015-07-15 20:52:19 +00:00
|
|
|
if (this._cache[cache])
|
2015-07-15 14:00:21 +00:00
|
|
|
{
|
2015-07-15 20:52:19 +00:00
|
|
|
for (var key in this._cache[cache])
|
2015-07-15 14:00:21 +00:00
|
|
|
{
|
|
|
|
if (key !== '__default' && key !== '__missing')
|
|
|
|
{
|
|
|
|
out.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
2014-02-14 23:51:49 +00:00
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
/////////////////////
|
|
|
|
// Remove Methods //
|
|
|
|
/////////////////////
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* Removes a canvas from the cache.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
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) {
|
2015-07-15 14:00:21 +00:00
|
|
|
|
|
|
|
delete this._cache.canvas[key];
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
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
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
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) {
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
if (removeFromPixi === undefined) { removeFromPixi = true; }
|
2014-09-16 11:20:03 +00:00
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
delete this._cache.image[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.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @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) {
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
delete this._cache.sound[key];
|
|
|
|
|
2015-05-03 12:42:41 +00:00
|
|
|
},
|
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2015-07-15 20:52:19 +00:00
|
|
|
* Removes a text file from the cache.
|
|
|
|
*
|
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
2013-10-02 14:05:55 +00:00
|
|
|
*
|
|
|
|
* @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) {
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
delete this._cache.text[key];
|
2014-02-21 18:48:06 +00:00
|
|
|
|
2014-09-18 23:22:00 +00:00
|
|
|
},
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
/**
|
|
|
|
* Removes a physics data file from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2014-02-14 23:51:49 +00:00
|
|
|
* @method Phaser.Cache#removePhysics
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removePhysics: function (key) {
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
delete this._cache.physics[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a tilemap from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2014-02-14 23:51:49 +00:00
|
|
|
* @method Phaser.Cache#removeTilemap
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeTilemap: function (key) {
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
delete this._cache.tilemap[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a binary file from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2014-02-14 23:51:49 +00:00
|
|
|
* @method Phaser.Cache#removeBinary
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBinary: function (key) {
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
delete this._cache.binary[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a bitmap data from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2014-02-14 23:51:49 +00:00
|
|
|
* @method Phaser.Cache#removeBitmapData
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBitmapData: function (key) {
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
delete this._cache.bitmapData[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a bitmap font from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2014-02-14 23:51:49 +00:00
|
|
|
* @method Phaser.Cache#removeBitmapFont
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeBitmapFont: function (key) {
|
2015-07-15 15:33:01 +00:00
|
|
|
|
|
|
|
delete this._cache.bitmapFont[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a json object from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeJSON
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeJSON: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.json[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a xml object from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeXML
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeXML: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.xml[key];
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
},
|
|
|
|
|
2015-07-15 14:00:21 +00:00
|
|
|
/**
|
|
|
|
* Removes a video from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 14:00:21 +00:00
|
|
|
* @method Phaser.Cache#removeVideo
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeVideo: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.video[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
/**
|
|
|
|
* Removes a shader from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeShader
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeShader: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.shader[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a Render Texture from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeRenderTexture
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeRenderTexture: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.renderTexture[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a Sprite Sheet from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeSpriteSheet
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeSpriteSheet: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.spriteSheet[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a Texture Atlas from the cache.
|
|
|
|
*
|
2015-07-15 20:52:19 +00:00
|
|
|
* Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere
|
|
|
|
* then it will persist in memory.
|
|
|
|
*
|
2015-07-15 15:33:01 +00:00
|
|
|
* @method Phaser.Cache#removeTextureAtlas
|
|
|
|
* @param {string} key - Key of the asset you want to remove.
|
|
|
|
*/
|
|
|
|
removeTextureAtlas: function (key) {
|
|
|
|
|
|
|
|
delete this._cache.atlas[key];
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
/**
|
2014-10-27 11:43:44 +00:00
|
|
|
* Resolves a URL to its absolute form and stores it in Cache._urlMap as long as Cache.autoResolveURL is set to `true`.
|
|
|
|
* This is then looked-up by the Cache.getURL and Cache.checkURL calls.
|
2014-10-05 02:20:28 +00:00
|
|
|
*
|
2014-10-27 11:43:44 +00:00
|
|
|
* @method Phaser.Cache#_resolveURL
|
2014-10-05 02:20:28 +00:00
|
|
|
* @private
|
2014-10-27 11:43:44 +00:00
|
|
|
* @param {string} url - The URL to resolve. This is appended to Loader.baseURL.
|
|
|
|
* @param {object} [data] - The data associated with the URL to be stored to the URL Map.
|
|
|
|
* @return {string} The resolved URL.
|
2014-10-05 02:20:28 +00:00
|
|
|
*/
|
2014-10-27 11:43:44 +00:00
|
|
|
_resolveURL: function (url, data) {
|
|
|
|
|
|
|
|
if (!this.autoResolveURL)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
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 = '';
|
|
|
|
|
2014-10-27 11:43:44 +00:00
|
|
|
// Record the URL to the map
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
this._urlMap[this._urlTemp] = data;
|
|
|
|
}
|
|
|
|
|
2014-10-05 02:20:28 +00:00
|
|
|
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.
|
2015-07-15 20:52:19 +00:00
|
|
|
* If an object in the cache has a `destroy` method it will also be called.
|
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 () {
|
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
for (var i = 0; i < this._cacheMap.length; i++)
|
2013-09-11 01:57:36 +00:00
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
var cache = this._cacheMap[i];
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2015-07-15 15:33:01 +00:00
|
|
|
for (var key in cache)
|
2015-02-09 20:27:58 +00:00
|
|
|
{
|
2015-07-15 15:33:01 +00:00
|
|
|
if (key !== '__default' && key !== '__missing')
|
|
|
|
{
|
|
|
|
if (cache[key]['destroy'])
|
|
|
|
{
|
|
|
|
cache[key].destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete cache[key];
|
|
|
|
}
|
2015-02-09 20:27:58 +00:00
|
|
|
}
|
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;
|