2013-08-28 06:02:55 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2013 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
* @module Phaser.Cache
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Phaser.Cache constructor.
|
2013-08-28 06:02:55 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.Cache
|
|
|
|
* @classdesc A game only has one instance of a Cache and it is used to store all externally loaded assets such
|
2013-08-28 06:02:55 +00:00
|
|
|
* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.
|
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-10-01 12:54:29 +00:00
|
|
|
* @property {Phaser.Game} game - Local reference to game.
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this.game = game;
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {object} game - Canvas key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._canvases = {};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-01 12:54:29 +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-10-01 12:54:29 +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-10-01 12:54:29 +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-10-01 12:54:29 +00:00
|
|
|
* @property {object} _text - Text key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-10 19:40:34 +00:00
|
|
|
this._text = {};
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {object} _tilemaps - Tilemap key-value container.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-12 03:24:01 +00:00
|
|
|
this._tilemaps = {};
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
this.addDefaultImage();
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} onSoundUnlock - Description.
|
|
|
|
*/
|
2013-09-11 10:33:27 +00:00
|
|
|
this.onSoundUnlock = new Phaser.Signal;
|
|
|
|
|
2013-09-10 19:40:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.Cache.prototype = {
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new canvas.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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-09-11 01:57:36 +00:00
|
|
|
/**
|
|
|
|
* Add a new canvas.
|
|
|
|
* @param key {string} Asset key for this canvas.
|
|
|
|
* @param canvas {RenderTexture} A RenderTexture.
|
|
|
|
*/
|
|
|
|
addRenderTexture: function (key, texture) {
|
|
|
|
|
2013-09-18 05:34:56 +00:00
|
|
|
var frame = new Phaser.Animation.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
|
|
|
/**
|
|
|
|
* Add a new sprite sheet.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key for the sprite sheet.
|
|
|
|
* @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.
|
|
|
|
* @param {number} frameMax - How many frames stored in the sprite sheet.
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
|
|
|
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) {
|
|
|
|
|
|
|
|
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2013-08-30 03:20:14 +00:00
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
2013-08-30 00:50:17 +00:00
|
|
|
|
2013-08-30 01:18:00 +00:00
|
|
|
this._images[key].frameData = Phaser.Animation.Parser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
|
|
|
* Add a new tilemap.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key for the texture atlas.
|
|
|
|
* @param {string} url - URL of this texture atlas file.
|
|
|
|
* @param {object} data - Extra texture atlas data.
|
|
|
|
* @param {object} atlasData - Texture atlas frames data.
|
2013-09-12 03:24:01 +00:00
|
|
|
*/
|
|
|
|
addTilemap: function (key, url, data, mapData, format) {
|
|
|
|
|
|
|
|
this._tilemaps[key] = { url: url, data: data, spriteSheet: true, mapData: mapData, format: format };
|
|
|
|
|
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* Add a new texture atlas.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key for the texture atlas.
|
|
|
|
* @param {string} url - URL of this texture atlas file.
|
|
|
|
* @param {object} data - Extra texture atlas data.
|
|
|
|
* @param {object} atlasData - Texture atlas frames data.
|
|
|
|
* @param {Description} format - Description.
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
|
|
|
addTextureAtlas: function (key, url, data, atlasData, format) {
|
|
|
|
|
|
|
|
this._images[key] = { url: url, data: data, spriteSheet: true };
|
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2013-08-30 03:20:14 +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-08-30 00:50:17 +00:00
|
|
|
this._images[key].frameData = Phaser.Animation.Parser.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-08-30 00:50:17 +00:00
|
|
|
this._images[key].frameData = Phaser.Animation.Parser.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-08-30 00:50:17 +00:00
|
|
|
this._images[key].frameData = Phaser.Animation.Parser.XMLData(this.game, atlasData, key);
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-10 22:51:35 +00:00
|
|
|
/**
|
|
|
|
* Add a new Bitmap Font.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key for the font texture.
|
|
|
|
* @param {string} url - URL of this font xml file.
|
|
|
|
* @param {object} data - Extra font data.
|
2013-09-10 22:51:35 +00:00
|
|
|
* @param xmlData {object} Texture atlas frames data.
|
|
|
|
*/
|
|
|
|
addBitmapFont: function (key, url, data, xmlData) {
|
|
|
|
|
|
|
|
this._images[key] = { url: url, data: data, spriteSheet: true };
|
|
|
|
|
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
|
|
|
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
|
|
|
|
|
|
|
Phaser.Loader.Parser.bitmapFont(this.game, xmlData, key);
|
|
|
|
// this._images[key].frameData = Phaser.Animation.Parser.XMLData(this.game, xmlData, key);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-10 10:09:25 +00:00
|
|
|
/**
|
|
|
|
* Adds a default image to be used when a key is wrong / missing.
|
|
|
|
* Is mapped to the key __default
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method addDefaultImage
|
2013-09-10 10:09:25 +00:00
|
|
|
*/
|
|
|
|
addDefaultImage: function () {
|
|
|
|
|
|
|
|
this._images['__default'] = { url: null, data: null, spriteSheet: false };
|
2013-09-18 05:34:56 +00:00
|
|
|
this._images['__default'].frame = new Phaser.Animation.Frame(0, 0, 0, 32, 32, '', '');
|
2013-09-10 10:09:25 +00:00
|
|
|
|
|
|
|
var base = new PIXI.BaseTexture();
|
|
|
|
base.width = 32;
|
|
|
|
base.height = 32;
|
|
|
|
base.hasLoaded = true; // avoids a hanging event listener
|
|
|
|
|
|
|
|
PIXI.BaseTextureCache['__default'] = base;
|
|
|
|
PIXI.TextureCache['__default'] = new PIXI.Texture(base);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* Add a new image.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method addImage
|
|
|
|
* @param {string} key - Asset key for the image.
|
|
|
|
* @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) {
|
|
|
|
|
|
|
|
this._images[key] = { url: url, data: data, spriteSheet: false };
|
2013-09-18 05:34:56 +00:00
|
|
|
this._images[key].frame = new Phaser.Animation.Frame(0, 0, 0, data.width, data.height, '', '');
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-08-30 00:50:17 +00:00
|
|
|
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
2013-08-30 03:20:14 +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
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new sound.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method addSound
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
* @param {string} url - URL of this sound file.
|
|
|
|
* @param {object} data - Extra sound data.
|
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 locked = this.game.sound.touchLocked;
|
|
|
|
var decoded = false;
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (audioTag)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
decoded = true;
|
|
|
|
}
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag };
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Reload a sound.
|
|
|
|
* @method 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
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method 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
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method updateSound
|
|
|
|
* @param {string} key - Asset key for the sound.
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
updateSound: function (key, property, value) {
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new decoded sound.
|
2013-10-01 12:54:29 +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;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new text data.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key for the text data.
|
|
|
|
* @param {string} url - URL of this text data file.
|
|
|
|
* @param {object} data - Extra text data.
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
|
|
|
addText: function (key, url, data) {
|
|
|
|
|
|
|
|
this._text[key] = {
|
|
|
|
url: url,
|
|
|
|
data: data
|
|
|
|
};
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get canvas by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the canvas you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The canvas you want.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-10 10:09:25 +00:00
|
|
|
/**
|
|
|
|
* Checks if an image key exists.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the image you want.
|
|
|
|
* @return {bool} True if the key exists, otherwise false.
|
2013-09-10 10:09:25 +00:00
|
|
|
*/
|
|
|
|
checkImageKey: function (key) {
|
|
|
|
|
|
|
|
if (this._images[key])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* Get image data by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the image you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The image data you want.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-12 03:24:01 +00:00
|
|
|
/**
|
|
|
|
* Get tilemap data by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the tilemap you want.
|
2013-09-12 03:24:01 +00:00
|
|
|
* @return {object} The tilemap data. The tileset image is in the data property, the map data in mapData.
|
|
|
|
*/
|
|
|
|
getTilemap: function (key) {
|
|
|
|
|
|
|
|
if (this._tilemaps[key])
|
|
|
|
{
|
|
|
|
return this._tilemaps[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* Get frame data by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the frame data you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The frame data you want.
|
|
|
|
*/
|
|
|
|
getFrameData: function (key) {
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
if (this._images[key] && this._images[key].frameData)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
return this._images[key].frameData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-11 16:32:53 +00:00
|
|
|
/**
|
|
|
|
* Get a single frame out of a frameData set by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the frame data you want.
|
2013-09-11 16:32:53 +00:00
|
|
|
* @return {object} The frame data you want.
|
|
|
|
*/
|
|
|
|
getFrameByIndex: function (key, frame) {
|
|
|
|
|
|
|
|
if (this._images[key] && this._images[key].frameData)
|
|
|
|
{
|
|
|
|
return this._images[key].frameData.getFrame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a single frame out of a frameData set by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the frame data you want.
|
2013-09-11 16:32:53 +00:00
|
|
|
* @return {object} The frame data you want.
|
|
|
|
*/
|
|
|
|
getFrameByName: function (key, frame) {
|
|
|
|
|
|
|
|
if (this._images[key] && this._images[key].frameData)
|
|
|
|
{
|
|
|
|
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-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the frame data you want.
|
2013-09-03 16:07:05 +00:00
|
|
|
* @return {object} The frame data you want.
|
|
|
|
*/
|
|
|
|
getFrame: function (key) {
|
|
|
|
|
|
|
|
if (this._images[key] && this._images[key].spriteSheet == false)
|
|
|
|
{
|
|
|
|
return this._images[key].frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2013-09-11 01:57:36 +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-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the frame data you want.
|
2013-09-11 01:57:36 +00:00
|
|
|
* @return {object} The frame data you want.
|
|
|
|
*/
|
|
|
|
getTextureFrame: function (key) {
|
|
|
|
|
|
|
|
if (this._textures[key])
|
|
|
|
{
|
|
|
|
return this._textures[key].frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a RenderTexture by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the RenderTexture you want.
|
2013-09-11 01:57:36 +00:00
|
|
|
* @return {object} The RenderTexture you want.
|
|
|
|
*/
|
|
|
|
getTexture: function (key) {
|
|
|
|
|
|
|
|
if (this._textures[key])
|
|
|
|
{
|
|
|
|
return this._textures[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
/**
|
|
|
|
* Get sound by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the sound you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The sound you want.
|
|
|
|
*/
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get sound data by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the sound you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The sound data you want.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an asset is decoded sound.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the sound you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The sound data you want.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an asset is decoded sound.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the sound you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The sound data you want.
|
|
|
|
*/
|
|
|
|
isSoundReady: function (key) {
|
2013-09-10 15:46:39 +00:00
|
|
|
|
|
|
|
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked == false);
|
|
|
|
|
2013-08-28 06:02:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether an asset is sprite sheet.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the sprite sheet you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The sprite sheet data you want.
|
|
|
|
*/
|
|
|
|
isSpriteSheet: 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].spriteSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get text data by key.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {string} key - Asset key of the text data you want.
|
2013-08-28 06:02:55 +00:00
|
|
|
* @return {object} The text data you want.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
getKeys: function (array) {
|
|
|
|
|
|
|
|
var output = [];
|
|
|
|
|
2013-09-10 11:46:14 +00:00
|
|
|
for (var item in array)
|
|
|
|
{
|
|
|
|
if (item !== '__default')
|
|
|
|
{
|
|
|
|
output.push(item);
|
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array containing all of the keys of Images in the Cache.
|
|
|
|
* @return {Array} The string based keys in the Cache.
|
|
|
|
*/
|
|
|
|
getImageKeys: function () {
|
|
|
|
return this.getKeys(this._images);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array containing all of the keys of Sounds in the Cache.
|
|
|
|
* @return {Array} The string based keys in the Cache.
|
|
|
|
*/
|
|
|
|
getSoundKeys: function () {
|
|
|
|
return this.getKeys(this._sounds);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array containing all of the keys of Text Files in the Cache.
|
|
|
|
* @return {Array} The string based keys in the Cache.
|
|
|
|
*/
|
|
|
|
getTextKeys: function () {
|
|
|
|
return this.getKeys(this._text);
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method removeCanvas
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeCanvas: function (key) {
|
|
|
|
delete this._canvases[key];
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method removeImage
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeImage: function (key) {
|
|
|
|
delete this._images[key];
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method removeSound
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeSound: function (key) {
|
|
|
|
delete this._sounds[key];
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method removeText
|
|
|
|
*/
|
2013-08-28 06:02:55 +00:00
|
|
|
removeText: function (key) {
|
|
|
|
delete this._text[key];
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up cache memory.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method 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)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
delete this._canvases[item['key']];
|
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._images)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
delete this._images[item['key']];
|
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._sounds)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
delete this._sounds[item['key']];
|
|
|
|
}
|
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
for (var item in this._text)
|
|
|
|
{
|
2013-08-28 06:02:55 +00:00
|
|
|
delete this._text[item['key']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|