phaser/docs/Cache.js.html

1342 lines
34 KiB
HTML
Raw Normal View History

2013-10-02 14:05:55 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Phaser Source: loader/Cache.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
<div class="container-fluid">
<div class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<a class="brand" href="index.html">Phaser</a>
<ul class="nav">
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
2013-10-02 14:05:55 +00:00
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.html">Phaser</a>
2013-10-02 14:05:55 +00:00
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li>
<a href="Phaser.Animation.html">Animation</a>
</li>
<li>
<a href="Phaser.AnimationManager.html">AnimationManager</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.AnimationParser.html">AnimationParser</a>
2013-10-02 14:05:55 +00:00
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li>
<a href="Phaser.Button.html">Button</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Cache.html">Cache</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.Camera.html">Camera</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.Canvas.html">Canvas</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.Circle.html">Circle</a>
2013-10-02 14:05:55 +00:00
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Color.html">Color</a>
2013-10-03 00:21:08 +00:00
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Device.html">Device</a>
2013-10-02 14:05:55 +00:00
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Easing.html">Easing</a>
</li>
<li>
<a href="Phaser.Easing.Back.html">Back</a>
</li>
<li>
<a href="Phaser.Easing.Bounce.html">Bounce</a>
</li>
<li>
<a href="Phaser.Easing.Circular.html">Circular</a>
</li>
<li>
<a href="Phaser.Easing.Cubic.html">Cubic</a>
</li>
<li>
<a href="Phaser.Easing.Elastic.html">Elastic</a>
</li>
<li>
<a href="Phaser.Easing.Exponential.html">Exponential</a>
</li>
<li>
<a href="Phaser.Easing.Linear.html">Linear</a>
</li>
<li>
<a href="Phaser.Easing.Quadratic.html">Quadratic</a>
</li>
<li>
<a href="Phaser.Easing.Quartic.html">Quartic</a>
</li>
<li>
<a href="Phaser.Easing.Quintic.html">Quintic</a>
</li>
<li>
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Events.html">Events</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Filter.html">Filter</a>
</li>
<li>
<a href="Phaser.Frame.html">Frame</a>
</li>
<li>
<a href="Phaser.FrameData.html">FrameData</a>
2013-10-03 00:21:08 +00:00
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Game.html">Game</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
<li>
<a href="Phaser.Graphics.html">Graphics</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Group.html">Group</a>
</li>
<li>
<a href="Phaser.Input.html">Input</a>
</li>
<li>
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
<li>
<a href="Phaser.Key.html">Key</a>
</li>
<li>
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
<li>
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
<li>
<a href="Phaser.Loader.html">Loader</a>
</li>
<li>
<a href="Phaser.LoaderParser.html">LoaderParser</a>
2013-10-02 14:05:55 +00:00
</li>
<li>
<a href="Phaser.Math.html">Math</a>
</li>
<li>
<a href="Phaser.Mouse.html">Mouse</a>
</li>
<li>
<a href="Phaser.MSPointer.html">MSPointer</a>
</li>
2013-10-02 19:18:24 +00:00
<li>
<a href="Phaser.Net.html">Net</a>
</li>
<li>
<a href="Phaser.Particles.html">Particles</a>
</li>
<li>
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Physics.html">Physics</a>
</li>
<li>
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
2013-10-25 16:30:37 +00:00
<li>
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Plugin.html">Plugin</a>
</li>
<li>
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
<li>
<a href="Phaser.Point.html">Point</a>
</li>
<li>
<a href="Phaser.Pointer.html">Pointer</a>
</li>
<li>
<a href="Phaser.Polygon.html">Polygon</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
<li>
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
<li>
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Signal.html">Signal</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.Sound.html">Sound</a>
</li>
<li>
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Sprite.html">Sprite</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Stage.html">Stage</a>
</li>
2013-10-03 00:21:08 +00:00
<li>
<a href="Phaser.StageScaleMode.html">StageScaleMode</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.State.html">State</a>
</li>
<li>
<a href="Phaser.StateManager.html">StateManager</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.Text.html">Text</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Tile.html">Tile</a>
</li>
<li>
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li>
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li>
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li>
<a href="Phaser.Tileset.html">Tileset</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
<li>
<a href="Phaser.Time.html">Time</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="Phaser.Timer.html">Timer</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.Touch.html">Touch</a>
</li>
<li>
<a href="Phaser.Tween.html">Tween</a>
</li>
<li>
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
<li>
<a href="Phaser.Utils.html">Utils</a>
</li>
<li>
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
2013-10-02 14:05:55 +00:00
<li>
<a href="Phaser.World.html">World</a>
</li>
<li>
<a href="SignalBinding.html">SignalBinding</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b
class="caret"></b></a>
<ul class="dropdown-menu ">
2013-10-25 15:54:40 +00:00
<li>
<a href="global.html#bottom">bottom</a>
</li>
<li>
<a href="global.html#HEXtoRGB">HEXtoRGB</a>
</li>
2013-11-28 15:57:09 +00:00
<li>
<a href="global.html#render">render</a>
</li>
<li>
<a href="global.html#renderXY">renderXY</a>
</li>
2013-10-25 15:54:40 +00:00
<li>
<a href="global.html#right">right</a>
</li>
</ul>
</li>
2013-10-02 14:05:55 +00:00
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: loader/Cache.js</h1>
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* @author Richard Davey &lt;rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Phaser.Cache constructor.
*
* @class Phaser.Cache
* @classdesc A game only has one instance of a Cache and it is used to store all externally loaded assets such
* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
Phaser.Cache = function (game) {
/**
2013-11-28 15:57:09 +00:00
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {object} game - Canvas key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._canvases = {};
/**
2013-11-28 15:57:09 +00:00
* @property {object} _images - Image key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._images = {};
/**
2013-11-28 15:57:09 +00:00
* @property {object} _textures - RenderTexture key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._textures = {};
/**
2013-11-28 15:57:09 +00:00
* @property {object} _sounds - Sound key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._sounds = {};
/**
2013-11-28 15:57:09 +00:00
* @property {object} _text - Text key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._text = {};
/**
2013-11-28 15:57:09 +00:00
* @property {object} _tilemaps - Tilemap key-value container.
* @private
*/
2013-10-02 14:05:55 +00:00
this._tilemaps = {};
/**
* @property {object} _tilesets - Tileset key-value container.
* @private
*/
this._tilesets = {};
2013-10-02 14:05:55 +00:00
2013-11-28 15:57:09 +00:00
/**
* @property {object} _bitmapDatas - BitmapData key-value container.
* @private
*/
this._bitmapDatas = {};
2013-10-02 14:05:55 +00:00
this.addDefaultImage();
2013-11-28 15:57:09 +00:00
this.addMissingImage();
2013-10-02 14:05:55 +00:00
/**
2013-11-28 15:57:09 +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-10-02 14:05:55 +00:00
};
Phaser.Cache.prototype = {
/**
* Add a new canvas object in to the cache.
* @method Phaser.Cache#addCanvas
* @param {string} key - Asset key for this canvas.
* @param {HTMLCanvasElement} canvas - Canvas DOM element.
* @param {CanvasRenderingContext2D} context - Render context of this canvas.
*/
addCanvas: function (key, canvas, context) {
this._canvases[key] = { canvas: canvas, context: context };
},
2013-11-28 15:57:09 +00:00
/**
* Add a BitmapData object in to the cache.
* @method Phaser.Cache#addBitmapData
* @param {string} key - Asset key for this BitmapData.
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
* @return {Phaser.BitmapData} The BitmapData object to be addded to the cache.
*/
addBitmapData: function (key, bitmapData) {
this._bitmapDatas[key] = bitmapData;
return bitmapData;
},
2013-10-02 14:05:55 +00:00
/**
* Add a new Phaser.RenderTexture in to the cache.
*
* @method Phaser.Cache#addRenderTexture
* @param {string} key - The unique key by which you will reference this object.
2013-11-28 15:57:09 +00:00
* @param {Phaser.Texture} texture - The texture to use as the base of the RenderTexture.
2013-10-02 14:05:55 +00:00
*/
addRenderTexture: function (key, texture) {
var frame = new Phaser.Frame(0, 0, 0, texture.width, texture.height, '', '');
2013-10-02 14:05:55 +00:00
this._textures[key] = { texture: texture, frame: frame };
},
/**
* Add a new sprite sheet in to the cache.
*
* @method Phaser.Cache#addSpriteSheet
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this sprite sheet file.
* @param {object} data - Extra sprite sheet data.
* @param {number} frameWidth - Width of the sprite sheet.
* @param {number} frameHeight - Height of the sprite sheet.
* @param {number} frameMax - How many frames stored in the sprite sheet.
*/
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) {
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax);
2013-10-02 14:05:55 +00:00
},
/**
* Add a new tile set in to the cache.
*
* @method Phaser.Cache#addTileset
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this tile set file.
* @param {object} data - Extra tile set data.
* @param {number} tileWidth - Width of the sprite sheet.
* @param {number} tileHeight - Height of the sprite sheet.
* @param {number} tileMax - How many tiles stored in the sprite sheet.
* @param {number} [tileMargin=0] - If the tiles have been drawn with a margin, specify the amount here.
* @param {number} [tileSpacing=0] - If the tiles have been drawn with spacing between them, specify the amount here.
*/
addTileset: function (key, url, data, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing) {
this._tilesets[key] = { url: url, data: data, tileWidth: tileWidth, tileHeight: tileHeight, tileMargin: tileMargin, tileSpacing: tileSpacing };
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
this._tilesets[key].tileData = Phaser.TilemapParser.tileset(this.game, key, tileWidth, tileHeight, tileMax, tileMargin, tileSpacing);
},
2013-10-02 14:05:55 +00:00
/**
* Add a new tilemap.
*
* @method Phaser.Cache#addTilemap
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of the tilemap image.
* @param {object} mapData - The tilemap data object.
* @param {number} format - The format of the tilemap data.
*/
addTilemap: function (key, url, mapData, format) {
2013-10-02 14:05:55 +00:00
this._tilemaps[key] = { url: url, data: mapData, format: format };
2013-10-02 14:05:55 +00:00
this._tilemaps[key].layers = Phaser.TilemapParser.parse(this.game, mapData, format);
2013-10-02 14:05:55 +00:00
},
/**
* Add a new texture atlas.
*
* @method Phaser.Cache#addTextureAtlas
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this texture atlas file.
* @param {object} data - Extra texture atlas data.
* @param {object} atlasData - Texture atlas frames data.
* @param {number} format - The format of the texture atlas.
*/
addTextureAtlas: function (key, url, data, atlasData, format) {
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]);
if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY)
{
this._images[key].frameData = Phaser.AnimationParser.JSONData(this.game, atlasData, key);
2013-10-02 14:05:55 +00:00
}
else if (format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
{
this._images[key].frameData = Phaser.AnimationParser.JSONDataHash(this.game, atlasData, key);
2013-10-02 14:05:55 +00:00
}
else if (format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING)
{
this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
2013-10-02 14:05:55 +00:00
}
},
/**
* Add a new Bitmap Font.
*
* @method Phaser.Cache#addBitmapFont
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this font xml file.
* @param {object} data - Extra font data.
* @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.LoaderParser.bitmapFont(this.game, xmlData, key);
// this._images[key].frameData = Phaser.AnimationParser.XMLData(this.game, xmlData, key);
2013-10-02 14:05:55 +00:00
},
/**
2013-11-28 15:57:09 +00:00
* Adds a default image to be used in special cases such as WebGL Filters. Is mapped to the key __default.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#addDefaultImage
*/
addDefaultImage: function () {
var img = new Image();
2013-11-28 15:57:09 +00:00
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==";
this._images['__default'] = { url: null, data: img, spriteSheet: false };
this._images['__default'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
2013-10-02 14:05:55 +00:00
PIXI.BaseTextureCache['__default'] = new PIXI.BaseTexture(img);
PIXI.TextureCache['__default'] = new PIXI.Texture(PIXI.BaseTextureCache['__default']);
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Adds an image to be used when a key is wrong / missing. Is mapped to the key __missing.
*
* @method Phaser.Cache#addMissingImage
*/
addMissingImage: function () {
var img = new Image();
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
this._images['__missing'] = { url: null, data: img, spriteSheet: false };
this._images['__missing'].frame = new Phaser.Frame(0, 0, 0, 32, 32, '', '');
PIXI.BaseTextureCache['__missing'] = new PIXI.BaseTexture(img);
PIXI.TextureCache['__missing'] = new PIXI.Texture(PIXI.BaseTextureCache['__missing']);
},
/**
* Add a new text data.
*
* @method Phaser.Cache#addText
* @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-11-28 15:57:09 +00:00
*/
addText: function (key, url, data) {
this._text[key] = {
url: url,
data: data
};
2013-10-02 14:05:55 +00:00
},
/**
* Add a new image.
*
* @method Phaser.Cache#addImage
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this image file.
* @param {object} data - Extra image data.
*/
addImage: function (key, url, data) {
this._images[key] = { url: url, data: data, spriteSheet: false };
2013-10-25 15:54:40 +00:00
this._images[key].frame = new Phaser.Frame(0, 0, 0, data.width, data.height, key, this.game.rnd.uuid());
2013-10-02 14:05:55 +00:00
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
},
/**
* Add a new sound.
*
* @method Phaser.Cache#addSound
* @param {string} key - Asset key for the sound.
* @param {string} url - URL of this sound file.
* @param {object} data - Extra sound data.
* @param {boolean} webAudio - True if the file is using web audio.
* @param {boolean} audioTag - True if the file is using legacy HTML audio.
*/
addSound: function (key, url, data, webAudio, audioTag) {
webAudio = webAudio || true;
audioTag = audioTag || false;
var decoded = false;
if (audioTag)
{
decoded = true;
}
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag };
},
/**
* Reload a sound.
* @method Phaser.Cache#reloadSound
* @param {string} key - Asset key for the sound.
*/
reloadSound: function (key) {
var _this = this;
if (this._sounds[key])
{
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();
}
},
/**
* Description.
* @method Phaser.Cache#reloadSoundComplete
* @param {string} key - Asset key for the sound.
*/
reloadSoundComplete: function (key) {
if (this._sounds[key])
{
this._sounds[key].locked = false;
this.onSoundUnlock.dispatch(key);
}
},
/**
* Description.
* @method Phaser.Cache#updateSound
* @param {string} key - Asset key for the sound.
*/
updateSound: function (key, property, value) {
if (this._sounds[key])
{
this._sounds[key][property] = value;
}
},
2013-11-28 15:57:09 +00:00
/**
* Add a new decoded sound.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#decodedSound
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key for the sound.
* @param {object} data - Extra sound data.
*/
2013-10-02 14:05:55 +00:00
decodedSound: function (key, data) {
this._sounds[key].data = data;
this._sounds[key].decoded = true;
this._sounds[key].isDecoding = false;
},
2013-11-28 15:57:09 +00:00
/**
* Get a canvas object from the cache by its key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getCanvas
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the canvas you want.
* @return {object} The canvas you want.
*/
2013-10-02 14:05:55 +00:00
getCanvas: function (key) {
if (this._canvases[key])
{
return this._canvases[key].canvas;
}
return null;
2013-11-28 15:57:09 +00:00
},
/**
* Get a BitmapData object from the cache by its key.
*
* @method Phaser.Cache#getBitmapData
* @param {string} key - Asset key of the BitmapData object you want.
* @return {Phaser.BitmapData} The requested BitmapData object if found, or null if not.
*/
getBitmapData: function (key) {
if (this._bitmapDatas[key])
{
return this._bitmapDatas[key];
}
return null;
2013-10-02 14:05:55 +00:00
},
/**
* Checks if an image key exists.
*
* @method Phaser.Cache#checkImageKey
* @param {string} key - Asset key of the image you want.
* @return {boolean} True if the key exists, otherwise false.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
checkImageKey: function (key) {
if (this._images[key])
{
return true;
}
return false;
},
2013-11-28 15:57:09 +00:00
/**
* Get image data by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getImage
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the image you want.
* @return {object} The image data you want.
*/
2013-10-02 14:05:55 +00:00
getImage: function (key) {
if (this._images[key])
{
return this._images[key].data;
}
return null;
2013-11-28 15:57:09 +00:00
2013-10-02 14:05:55 +00:00
},
/**
* Get tile set image data by key.
*
* @method Phaser.Cache#getTileSetImage
* @param {string} key - Asset key of the image you want.
* @return {object} The image data you want.
2013-11-28 15:57:09 +00:00
*/
getTilesetImage: function (key) {
if (this._tilesets[key])
{
return this._tilesets[key].data;
}
return null;
},
/**
* Get tile set image data by key.
*
* @method Phaser.Cache#getTileset
* @param {string} key - Asset key of the image you want.
* @return {Phaser.Tileset} The tileset data. The tileset image is in the data property, the tile data in tileData.
2013-11-28 15:57:09 +00:00
*/
getTileset: function (key) {
if (this._tilesets[key])
{
return this._tilesets[key].tileData;
}
return null;
},
2013-10-02 14:05:55 +00:00
/**
* Get tilemap data by key.
*
* @method Phaser.Cache#getTilemap
* @param {string} key - Asset key of the tilemap you want.
* @return {Object} The tilemap data. The tileset image is in the data property, the map data in mapData.
2013-10-02 14:05:55 +00:00
*/
getTilemapData: function (key) {
2013-10-02 14:05:55 +00:00
if (this._tilemaps[key])
{
return this._tilemaps[key];
}
return null;
},
2013-11-28 15:57:09 +00:00
/**
* Get frame data by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getFrameData
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the frame data you want.
* @return {Phaser.FrameData} The frame data you want.
*/
2013-10-02 14:05:55 +00:00
getFrameData: function (key) {
if (this._images[key] && this._images[key].frameData)
{
return this._images[key].frameData;
}
return null;
},
/**
* Get a single frame out of a frameData set by key.
*
* @method Phaser.Cache#getFrameByIndex
* @param {string} key - Asset key of the frame data you want.
* @return {Phaser.Frame} The frame data you want.
2013-10-02 14:05:55 +00:00
*/
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.
*
* @method Phaser.Cache#getFrameByName
* @param {string} key - Asset key of the frame data you want.
* @return {Phaser.Frame} The frame data you want.
2013-10-02 14:05:55 +00:00
*/
getFrameByName: function (key, frame) {
if (this._images[key] && this._images[key].frameData)
{
return this._images[key].frameData.getFrameByName(frame);
}
return null;
},
/**
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
*
* @method Phaser.Cache#getFrame
* @param {string} key - Asset key of the frame data you want.
* @return {Phaser.Frame} The frame data you want.
2013-10-02 14:05:55 +00:00
*/
getFrame: function (key) {
2013-11-28 15:57:09 +00:00
if (this._images[key] && this._images[key].spriteSheet === false)
2013-10-02 14:05:55 +00:00
{
return this._images[key].frame;
}
return null;
},
/**
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
*
* @method Phaser.Cache#getTextureFrame
* @param {string} key - Asset key of the frame data you want.
* @return {Phaser.Frame} The frame data you want.
2013-10-02 14:05:55 +00:00
*/
getTextureFrame: function (key) {
if (this._textures[key])
{
return this._textures[key].frame;
}
return null;
},
/**
* Get a RenderTexture by key.
*
* @method Phaser.Cache#getTexture
* @param {string} key - Asset key of the RenderTexture you want.
* @return {Phaser.RenderTexture} The RenderTexture you want.
*/
getTexture: function (key) {
if (this._textures[key])
{
return this._textures[key];
}
return null;
},
2013-11-28 15:57:09 +00:00
/**
* Get sound by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getSound
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the sound you want.
* @return {Phaser.Sound} The sound you want.
*/
2013-10-02 14:05:55 +00:00
getSound: function (key) {
if (this._sounds[key])
{
return this._sounds[key];
}
return null;
},
2013-11-28 15:57:09 +00:00
/**
* Get sound data by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getSoundData
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the sound you want.
* @return {object} The sound data you want.
*/
2013-10-02 14:05:55 +00:00
getSoundData: function (key) {
if (this._sounds[key])
{
return this._sounds[key].data;
}
return null;
},
2013-11-28 15:57:09 +00:00
/**
* Check if the given sound has finished decoding.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#isSoundDecoded
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the sound you want.
* @return {boolean} The decoded state of the Sound object.
*/
2013-10-02 14:05:55 +00:00
isSoundDecoded: function (key) {
if (this._sounds[key])
{
return this._sounds[key].decoded;
}
},
2013-11-28 15:57:09 +00:00
/**
* Check if the given sound is ready for playback. A sound is considered ready when it has finished decoding and the device is no longer touch locked.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#isSoundReady
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the sound you want.
* @return {boolean} True if the sound is decoded and the device is not touch locked.
*/
2013-10-02 14:05:55 +00:00
isSoundReady: function (key) {
2013-11-28 15:57:09 +00:00
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false);
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Check whether an image asset is sprite sheet or not.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#isSpriteSheet
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the sprite sheet you want.
* @return {boolean} True if the image is a sprite sheet.
*/
2013-10-02 14:05:55 +00:00
isSpriteSheet: function (key) {
if (this._images[key])
{
return this._images[key].spriteSheet;
}
return false;
},
2013-11-28 15:57:09 +00:00
/**
* Get text data by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getText
2013-11-28 15:57:09 +00:00
* @param {string} key - Asset key of the text data you want.
* @return {object} The text data you want.
*/
2013-10-02 14:05:55 +00:00
getText: function (key) {
if (this._text[key])
{
return this._text[key].data;
}
return null;
},
/**
* Get the cache keys from a given array of objects.
* Normally you don't call this directly but instead use getImageKeys, getSoundKeys, etc.
*
* @method Phaser.Cache#getKeys
* @param {Array} array - An array of items to return the keys for.
* @return {Array} The array of item keys.
*/
getKeys: function (array) {
var output = [];
for (var item in array)
{
if (item !== '__default')
{
output.push(item);
}
}
return output;
},
2013-11-28 15:57:09 +00:00
/**
* Returns an array containing all of the keys of Images in the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getImageKeys
2013-11-28 15:57:09 +00:00
* @return {Array} The string based keys in the Cache.
*/
2013-10-02 14:05:55 +00:00
getImageKeys: function () {
2013-11-28 15:57:09 +00:00
return this.getKeys(this._images);
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Returns an array containing all of the keys of Sounds in the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getSoundKeys
2013-11-28 15:57:09 +00:00
* @return {Array} The string based keys in the Cache.
*/
2013-10-02 14:05:55 +00:00
getSoundKeys: function () {
2013-11-28 15:57:09 +00:00
return this.getKeys(this._sounds);
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Returns an array containing all of the keys of Text Files in the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getTextKeys
2013-11-28 15:57:09 +00:00
* @return {Array} The string based keys in the Cache.
*/
2013-10-02 14:05:55 +00:00
getTextKeys: function () {
2013-11-28 15:57:09 +00:00
return this.getKeys(this._text);
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Removes a canvas from the cache.
2013-10-02 14:05:55 +00:00
*
2013-11-28 15:57:09 +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-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
removeCanvas: function (key) {
delete this._canvases[key];
},
/**
* Removes an image from the cache.
*
* @method Phaser.Cache#removeImage
* @param {string} key - Key of the asset you want to remove.
*/
removeImage: function (key) {
delete this._images[key];
},
/**
* Removes a sound from the cache.
*
* @method Phaser.Cache#removeSound
* @param {string} key - Key of the asset you want to remove.
*/
removeSound: function (key) {
delete this._sounds[key];
},
/**
* Removes a text from the cache.
*
* @method Phaser.Cache#removeText
* @param {string} key - Key of the asset you want to remove.
*/
removeText: function (key) {
delete this._text[key];
},
2013-11-28 15:57:09 +00:00
/**
* Clears the cache. Removes every local cache object reference.
2013-10-02 14:05:55 +00:00
*
2013-11-28 15:57:09 +00:00
* @method Phaser.Cache#destroy
*/
2013-10-02 14:05:55 +00:00
destroy: function () {
for (var item in this._canvases)
{
delete this._canvases[item['key']];
}
for (var item in this._images)
{
delete this._images[item['key']];
}
for (var item in this._sounds)
{
delete this._sounds[item['key']];
}
for (var item in this._text)
{
delete this._text[item['key']];
}
}
};
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
Phaser Copyright © 2012-2013 Photon Storm Ltd.
</span>
<br />
<span class="jsdoc-message">
2013-10-25 15:54:40 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
2013-11-28 15:57:09 +00:00
on Thu Nov 28 2013 15:56:25 GMT-0000 (GMT) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
2013-10-02 14:05:55 +00:00
</span>
</footer>
</div>
<br clear="both">
</div>
</div>
<script src="scripts/sunlight.js"></script>
<script src="scripts/sunlight.javascript.js"></script>
<script src="scripts/sunlight-plugin.doclinks.js"></script>
<script src="scripts/sunlight-plugin.linenumbers.js"></script>
<script src="scripts/sunlight-plugin.menu.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.scrollTo.js"></script>
<script src="scripts/jquery.localScroll.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
<script>
$( function () {
$( "#toc" ).toc( {
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
</script>
</body>
</html>