phaser/docs/Cache.js.html

1794 lines
47 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 ">
2014-04-10 22:13:43 +00:00
<li class="class-depth-0">
<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 ">
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Animation.html">Animation</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.AnimationManager.html">AnimationManager</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.AnimationParser.html">AnimationParser</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-29 14:39:02 +00:00
<li class="class-depth-1">
<a href="Phaser.ArrayList.html">ArrayList</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Button.html">Button</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Cache.html">Cache</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Camera.html">Camera</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Canvas.html">Canvas</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Circle.html">Circle</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Color.html">Color</a>
2013-10-03 00:21:08 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Device.html">Device</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Easing.html">Easing</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Back.html">Back</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Bounce.html">Bounce</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Circular.html">Circular</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Cubic.html">Cubic</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Elastic.html">Elastic</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Exponential.html">Exponential</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Linear.html">Linear</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Quadratic.html">Quadratic</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Quartic.html">Quartic</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Quintic.html">Quintic</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Ellipse.html">Ellipse</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Events.html">Events</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Filter.html">Filter</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Frame.html">Frame</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.FrameData.html">FrameData</a>
2013-10-03 00:21:08 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Game.html">Game</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.GameObjectCreator.html">GameObjectCreator</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.GamepadButton.html">GamepadButton</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Graphics.html">Graphics</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Group.html">Group</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Image.html">Image</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Input.html">Input</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Key.html">Key</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.Line.html">Line</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Loader.html">Loader</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.LoaderParser.html">LoaderParser</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Math.html">Math</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Mouse.html">Mouse</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.MSPointer.html">MSPointer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Net.html">Net</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Particle.html">Particle</a>
</li>
<li class="class-depth-1">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Particles.html">Particles</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Physics.html">Physics</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Physics.Ninja.html">Ninja</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.AABB.html">AABB</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Body.html">Body</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Circle.html">Circle</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Tile.html">Tile</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Physics.P2.html">P2</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Body.html">Body</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.BodyDebug.html">BodyDebug</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.DistanceConstraint.html">DistanceConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.FixtureList.html">FixtureList</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.GearConstraint.html">GearConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.InversePointProxy.html">InversePointProxy</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.LockConstraint.html">LockConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Material.html">Material</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PointProxy.html">PointProxy</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PrismaticConstraint.html">PrismaticConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RevoluteConstraint.html">RevoluteConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Spring.html">Spring</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Plugin.html">Plugin</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Point.html">Point</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Pointer.html">Pointer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Polygon.html">Polygon</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.RetroFont.html">RetroFont</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.ScaleManager.html">ScaleManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Signal.html">Signal</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SignalBinding.html">SignalBinding</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.Sound.html">Sound</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Sprite.html">Sprite</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Stage.html">Stage</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.State.html">State</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.StateManager.html">StateManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Text.html">Text</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tile.html">Tile</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tileset.html">Tileset</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Time.html">Time</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Timer.html">Timer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Touch.html">Touch</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Tween.html">Tween</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Utils.html">Utils</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.World.html">World</a>
</li>
</ul>
</li>
</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>
2014-02-05 06:29:17 +00:00
* @copyright 2014 Photon Storm Ltd.
2013-10-02 14:05:55 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Phaser.Cache constructor.
*
2014-02-05 06:29:17 +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 as images, sounds and data files as a result of Loader calls. Cached items use string based keys for look-up.
2013-10-02 14:05:55 +00:00
* @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 = {};
/**
* @property {object} _text - Text key-value container.
* @private
*/
this._json = {};
/**
* @property {object} _physics - Physics data key-value container.
* @private
*/
this._physics = {};
2013-10-02 14:05:55 +00:00
/**
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 = {};
/**
2014-02-05 06:29:17 +00:00
* @property {object} _binary - Binary file key-value container.
* @private
*/
2014-02-05 06:29:17 +00:00
this._binary = {};
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 = {};
/**
* @property {object} _bitmapFont - BitmapFont key-value container.
* @private
*/
this._bitmapFont = {};
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
};
/**
* @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;
/**
* @constant
* @type {number}
*/
Phaser.Cache.JSON = 11;
2013-10-02 14:05:55 +00:00
Phaser.Cache.prototype = {
/**
* Add a new canvas object in to the cache.
*
2013-10-02 14:05:55 +00:00
* @method Phaser.Cache#addCanvas
* @param {string} key - Asset key for this canvas.
* @param {HTMLCanvasElement} canvas - Canvas DOM element.
* @param {CanvasRenderingContext2D} context - Render context of this canvas.
*/
addCanvas: function (key, canvas, context) {
this._canvases[key] = { canvas: canvas, context: context };
},
2014-02-05 06:29:17 +00:00
/**
* Add a binary object in to the cache.
*
2014-02-05 06:29:17 +00:00
* @method Phaser.Cache#addBinary
* @param {string} key - Asset key for this binary data.
* @param {object} binaryData - The binary object to be addded to the cache.
*/
addBinary: function (key, binaryData) {
this._binary[key] = binaryData;
},
2013-11-28 15:57:09 +00:00
/**
* Add a BitmapData object in to the cache.
*
2013-11-28 15:57:09 +00:00
* @method Phaser.Cache#addBitmapData
* @param {string} key - Asset key for this BitmapData.
* @param {Phaser.BitmapData} bitmapData - The BitmapData object to be addded to the cache.
* @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.
2014-02-05 06:29:17 +00:00
* @param {number} [frameMax=-1] - How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly.
* @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here.
* @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
2013-10-02 14:05:55 +00:00
*/
2014-02-05 06:29:17 +00:00
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax, margin, spacing) {
2013-10-02 14:05:55 +00:00
2014-02-05 06:29:17 +00:00
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight, margin: margin, spacing: spacing };
2013-10-02 14:05:55 +00:00
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
2014-02-05 06:29:17 +00:00
this._images[key].frameData = Phaser.AnimationParser.spriteSheet(this.game, key, frameWidth, frameHeight, frameMax, margin, spacing);
},
2013-10-02 14:05:55 +00:00
/**
* Add a new tilemap to the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#addTilemap
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of the tilemap image.
2014-02-05 06:29:17 +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.
*/
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
},
/**
* Add a new texture atlas to the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#addTextureAtlas
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this texture atlas file.
* @param {object} data - Extra texture atlas data.
* @param {object} atlasData - Texture atlas frames data.
* @param {number} format - The format of the texture atlas.
*/
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 to the Cache.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#addBitmapFont
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of this font xml file.
* @param {object} data - Extra font data.
* @param {object} xmlData - Texture atlas frames data.
* @param {number} [xSpacing=0] - If you'd like to add additional horizontal spacing between the characters then set the pixel value here.
* @param {number} [ySpacing=0] - If you'd like to add additional vertical spacing between the lines then set the pixel value here.
2013-10-02 14:05:55 +00:00
*/
addBitmapFont: function (key, url, data, xmlData, xSpacing, ySpacing) {
2013-10-02 14:05:55 +00:00
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, xSpacing, ySpacing);
},
/**
* Add a new physics data object to the Cache.
*
* @method Phaser.Cache#addTilemap
* @param {string} key - The unique key by which you will reference this object.
* @param {string} url - URL of the physics json data.
* @param {object} JSONData - The physics data object (a JSON file).
* @param {number} format - The format of the physics data.
*/
addPhysicsData: function (key, url, JSONData, format) {
this._physics[key] = { url: url, data: JSONData, format: format };
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
* @protected
2013-10-02 14:05:55 +00:00
*/
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
* @protected
2013-11-28 15:57:09 +00:00
*/
addMissingImage: function () {
var img = new Image();
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==";
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 json object into the cache.
*
* @method Phaser.Cache#addJSON
* @param {string} key - Asset key for the text data.
* @param {string} url - URL of this text data file.
* @param {object} data - Extra text data.
*/
addJSON: function (key, url, data) {
this._json[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;
}
2014-02-05 06:29:17 +00:00
this._sounds[key] = { url: url, data: data, isDecoding: false, decoded: decoded, webAudio: webAudio, audioTag: audioTag, locked: this.game.sound.touchLocked };
2013-10-02 14:05:55 +00:00
},
/**
* Reload a sound.
2014-02-05 06:29:17 +00:00
*
2013-10-02 14:05:55 +00:00
* @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();
}
},
/**
2014-02-05 06:29:17 +00:00
* Fires the onSoundUnlock event when the sound has completed reloading.
*
2013-10-02 14:05:55 +00:00
* @method Phaser.Cache#reloadSoundComplete
* @param {string} key - Asset key for the sound.
*/
reloadSoundComplete: function (key) {
if (this._sounds[key])
{
this._sounds[key].locked = false;
this.onSoundUnlock.dispatch(key);
}
},
/**
2014-02-05 06:29:17 +00:00
* Updates the sound object in the cache.
*
2013-10-02 14:05:55 +00:00
* @method Phaser.Cache#updateSound
* @param {string} key - Asset key for the sound.
*/
updateSound: function (key, property, value) {
2013-10-02 14:05:55 +00:00
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the canvas to retrieve from the Cache.
* @return {object} The canvas object.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getCanvas: function (key) {
if (this._canvases[key])
{
return this._canvases[key].canvas;
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getCanvas: Invalid key: "' + key + '"');
}
2013-11-28 15:57:09 +00:00
},
/**
* Get a BitmapData object from the cache by its key.
*
* @method Phaser.Cache#getBitmapData
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the BitmapData object to retrieve from the Cache.
2013-11-28 15:57:09 +00:00
* @return {Phaser.BitmapData} The requested BitmapData object if found, or null if not.
*/
getBitmapData: function (key) {
if (this._bitmapDatas[key])
{
return this._bitmapDatas[key];
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getBitmapData: Invalid key: "' + key + '"');
}
2013-11-28 15:57:09 +00:00
2013-10-02 14:05:55 +00:00
},
/**
* Get a BitmapFont object from the cache by its key.
*
* @method Phaser.Cache#getBitmapFont
* @param {string} key - Asset key of the BitmapFont object to retrieve from the Cache.
* @return {Phaser.BitmapFont} The requested BitmapFont object if found, or null if not.
*/
getBitmapFont: function (key) {
if (this._bitmapFont[key])
{
return this._bitmapFont[key];
}
else
{
console.warn('Phaser.Cache.getBitmapFont: Invalid key: "' + key + '"');
}
},
/**
2014-04-10 22:13:43 +00:00
* Get a physics data object from the cache by its key. You can get either the entire data set, a single object or a single fixture of an object from it.
*
* @method Phaser.Cache#getPhysicsData
* @param {string} key - Asset key of the physics data object to retrieve from the Cache.
* @param {string} [object=null] - If specified it will return just the physics object that is part of the given key, if null it will return them all.
2014-04-10 22:13:43 +00:00
* @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.
*/
2014-04-10 22:13:43 +00:00
getPhysicsData: function (key, object, fixtureKey) {
if (typeof object === 'undefined' || object === null)
{
// Get 'em all
if (this._physics[key])
{
return this._physics[key].data;
}
else
{
console.warn('Phaser.Cache.getPhysicsData: Invalid key: "' + key + '"');
}
}
else
{
if (this._physics[key] && this._physics[key].data[object])
{
2014-04-10 22:13:43 +00:00
var fixtures = this._physics[key].data[object];
//try to find a fixture by it's fixture key if given
if (fixtures && fixtureKey)
2014-04-10 22:13:43 +00:00
{
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-10-02 14:05:55 +00:00
/**
* Checks if an image key exists.
*
* @method Phaser.Cache#checkImageKey
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the image to check is in the Cache.
2013-10-02 14:05:55 +00:00
* @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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the image to retrieve from the Cache.
* @return {object} The image data.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getImage: function (key) {
if (this._images[key])
{
return this._images[key].data;
}
2014-02-05 06:29:17 +00:00
else
{
2014-02-05 06:29:17 +00:00
console.warn('Phaser.Cache.getImage: Invalid key: "' + key + '"');
}
},
2013-10-02 14:05:55 +00:00
/**
* Get tilemap data by key.
*
* @method Phaser.Cache#getTilemap
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the tilemap data to retrieve from the Cache.
* @return {Object} The raw tilemap data in CSV or JSON format.
2013-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];
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getTilemapData: Invalid key: "' + key + '"');
}
2013-10-02 14:05:55 +00:00
},
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
* @return {Phaser.FrameData} The frame data.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getFrameData: function (key) {
if (this._images[key] && this._images[key].frameData)
2013-10-02 14:05:55 +00:00
{
return this._images[key].frameData;
}
return null;
},
/**
* Replaces a set of frameData with a new Phaser.FrameData object.
*
* @method Phaser.Cache#updateFrameData
* @param {string} key - The unique key by which you will reference this object.
* @param {number} frameData - The new FrameData.
*/
updateFrameData: function (key, frameData) {
if (this._images[key])
{
this._images[key].spriteSheet = true;
this._images[key].frameData = frameData;
}
},
2013-10-02 14:05:55 +00:00
/**
* Get a single frame out of a frameData set by key.
*
* @method Phaser.Cache#getFrameByIndex
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
* @return {Phaser.Frame} The frame object.
2013-10-02 14:05:55 +00:00
*/
getFrameByIndex: function (key, frame) {
if (this._images[key] && this._images[key].frameData)
2013-10-02 14:05:55 +00:00
{
return this._images[key].frameData.getFrame(frame);
}
return null;
},
/**
* Get a single frame out of a frameData set by key.
*
* @method Phaser.Cache#getFrameByName
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
* @return {Phaser.Frame} The frame object.
2013-10-02 14:05:55 +00:00
*/
getFrameByName: function (key, frame) {
if (this._images[key] && this._images[key].frameData)
2013-10-02 14:05:55 +00:00
{
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the frame data to retrieve from the Cache.
* @return {Phaser.Frame} The frame data.
2013-10-02 14:05:55 +00:00
*/
getFrame: function (key) {
if (this._images[key] && this._images[key].spriteSheet === false)
2013-10-02 14:05:55 +00:00
{
return this._images[key].frame;
}
return null;
},
/**
2014-02-05 06:29:17 +00:00
* Get a single texture frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getTextureFrame
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the frame to retrieve from the Cache.
* @return {Phaser.Frame} The frame data.
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the RenderTexture to retrieve from the Cache.
* @return {Phaser.RenderTexture} The RenderTexture object.
2013-10-02 14:05:55 +00:00
*/
getTexture: function (key) {
if (this._textures[key])
{
return this._textures[key];
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getTexture: Invalid key: "' + key + '"');
}
2013-10-02 14:05:55 +00:00
},
2013-11-28 15:57:09 +00:00
/**
* Get sound by key.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getSound
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the sound to retrieve from the Cache.
* @return {Phaser.Sound} The sound object.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getSound: function (key) {
if (this._sounds[key])
{
return this._sounds[key];
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getSound: Invalid key: "' + key + '"');
}
2013-10-02 14:05:55 +00:00
},
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the sound to retrieve from the Cache.
* @return {object} The sound data.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getSoundData: function (key) {
if (this._sounds[key])
{
return this._sounds[key].data;
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getSoundData: Invalid key: "' + key + '"');
}
2013-10-02 14:05:55 +00:00
},
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the sound in the Cache.
2013-11-28 15:57:09 +00:00
* @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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the sound in the Cache.
2013-11-28 15:57:09 +00:00
* @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) {
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
2014-02-05 06:29:17 +00:00
* @param {string} key - Asset key of the text data to retrieve from the Cache.
* @return {object} The text data.
2013-11-28 15:57:09 +00:00
*/
2013-10-02 14:05:55 +00:00
getText: function (key) {
if (this._text[key])
{
return this._text[key].data;
}
2014-02-05 06:29:17 +00:00
else
{
console.warn('Phaser.Cache.getText: Invalid key: "' + key + '"');
}
2014-02-05 06:29:17 +00:00
},
2013-10-02 14:05:55 +00:00
/**
* Get a JSON object by key from the cache.
*
* @method Phaser.Cache#getJSON
* @param {string} key - Asset key of the json object to retrieve from the Cache.
* @return {object} The JSON object.
*/
getJSON: function (key) {
if (this._json[key])
{
return this._json[key].data;
}
else
{
console.warn('Phaser.Cache.getJSON: Invalid key: "' + key + '"');
}
},
2014-02-05 06:29:17 +00:00
/**
* Get binary data by key.
*
* @method Phaser.Cache#getBinary
* @param {string} key - Asset key of the binary data object to retrieve from the Cache.
* @return {object} The binary data object.
*/
getBinary: function (key) {
if (this._binary[key])
{
return this._binary[key];
}
else
{
console.warn('Phaser.Cache.getBinary: Invalid key: "' + key + '"');
}
2013-10-02 14:05:55 +00:00
},
/**
* Gets all keys used by the Cache for the given data type.
2013-10-02 14:05:55 +00:00
*
* @method Phaser.Cache#getKeys
* @param {number} [type=Phaser.Cache.IMAGE] - The type of Cache keys you wish to get. Can be Cache.CANVAS, Cache.IMAGE, Cache.SOUND, etc.
2013-10-02 14:05:55 +00:00
* @return {Array} The array of item keys.
*/
getKeys: function (type) {
var array = null;
switch (type)
{
case Phaser.Cache.CANVAS:
array = this._canvases;
break;
case Phaser.Cache.IMAGE:
array = this._images;
break;
case Phaser.Cache.TEXTURE:
array = this._textures;
break;
case Phaser.Cache.SOUND:
array = this._sounds;
break;
case Phaser.Cache.TEXT:
array = this._text;
break;
case Phaser.Cache.PHYSICS:
array = this._physics;
break;
case Phaser.Cache.TILEMAP:
array = this._tilemaps;
break;
case Phaser.Cache.BINARY:
array = this._binary;
break;
case Phaser.Cache.BITMAPDATA:
array = this._bitmapDatas;
break;
case Phaser.Cache.BITMAPFONT:
array = this._bitmapFont;
break;
case Phaser.Cache.JSON:
array = this._json;
break;
}
if (!array)
{
return;
}
2013-10-02 14:05:55 +00:00
var output = [];
for (var item in array)
{
if (item !== '__default' && item !== '__missing')
2013-10-02 14:05:55 +00:00
{
output.push(item);
}
}
return output;
},
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];
},
/**
* Removes a json object from the cache.
*
* @method Phaser.Cache#removeJSON
* @param {string} key - Key of the asset you want to remove.
*/
removeJSON: function (key) {
delete this._json[key];
},
/**
* Removes a physics data file from the cache.
*
* @method Phaser.Cache#removePhysics
* @param {string} key - Key of the asset you want to remove.
*/
removePhysics: function (key) {
delete this._physics[key];
},
/**
* Removes a tilemap from the cache.
*
* @method Phaser.Cache#removeTilemap
* @param {string} key - Key of the asset you want to remove.
*/
removeTilemap: function (key) {
delete this._tilemaps[key];
},
/**
* Removes a binary file from the cache.
*
* @method Phaser.Cache#removeBinary
* @param {string} key - Key of the asset you want to remove.
*/
removeBinary: function (key) {
delete this._binary[key];
},
/**
* Removes a bitmap data from the cache.
*
* @method Phaser.Cache#removeBitmapData
* @param {string} key - Key of the asset you want to remove.
*/
removeBitmapData: function (key) {
delete this._bitmapDatas[key];
},
/**
* Removes a bitmap font from the cache.
*
* @method Phaser.Cache#removeBitmapFont
* @param {string} key - Key of the asset you want to remove.
*/
removeBitmapFont: function (key) {
delete this._bitmapFont[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];
2013-10-02 14:05:55 +00:00
}
for (var item in this._images)
{
if (item !== '__default' && item !== '__missing')
{
delete this._images[item];
}
2013-10-02 14:05:55 +00:00
}
for (var item in this._sounds)
{
delete this._sounds[item];
2013-10-02 14:05:55 +00:00
}
for (var item in this._text)
{
delete this._text[item];
2013-10-02 14:05:55 +00:00
}
for (var item in this._json)
{
delete this._json[item];
}
for (var item in this._textures)
{
delete this._textures[item];
}
for (var item in this._physics)
{
delete this._physics[item];
}
for (var item in this._tilemaps)
{
delete this._tilemaps[item];
}
for (var item in this._binary)
{
delete this._binary[item];
}
for (var item in this._bitmapDatas)
{
delete this._bitmapDatas[item];
}
for (var item in this._bitmapFont)
{
delete this._bitmapFont[item];
}
2013-10-02 14:05:55 +00:00
}
};
2014-02-05 06:29:17 +00:00
Phaser.Cache.prototype.constructor = Phaser.Cache;
2013-10-02 14:05:55 +00:00
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
2014-02-05 06:29:17 +00:00
Phaser Copyright © 2012-2014 Photon Storm Ltd.
2013-10-02 14:05:55 +00:00
</span>
<br />
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-dev</a>
2014-04-29 14:39:02 +00:00
on Tue Apr 29 2014 14:51:16 GMT+0100 (BST) 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( {
2014-04-10 22:13:43 +00:00
anchorName : function(i, heading, prefix) {
return $(heading).attr("id") || ( prefix + i );
},
2013-10-02 14:05:55 +00:00
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>