mirror of
https://github.com/wassname/phaser.git
synced 2026-07-09 00:20:17 +08:00
Adding docs.
This commit is contained in:
+121
-77
@@ -1,60 +1,68 @@
|
||||
/**
|
||||
* Cache
|
||||
* @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.
|
||||
*
|
||||
* A game only has one instance of a Cache and it is used to store all externally loaded assets such
|
||||
* @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.
|
||||
*
|
||||
* @package Phaser.Cache
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Cache = function (game) {
|
||||
|
||||
/**
|
||||
* Local reference to Game.
|
||||
*/
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Canvas key-value container.
|
||||
* @type {object}
|
||||
* @private
|
||||
*/
|
||||
/**
|
||||
* @property {object} game - Canvas key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._canvases = {};
|
||||
|
||||
/**
|
||||
* Image key-value container.
|
||||
* @type {object}
|
||||
*/
|
||||
* @property {object} _images - Image key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._images = {};
|
||||
|
||||
/**
|
||||
* RenderTexture key-value container.
|
||||
* @type {object}
|
||||
*/
|
||||
* @property {object} _textures - RenderTexture key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._textures = {};
|
||||
|
||||
/**
|
||||
* Sound key-value container.
|
||||
* @type {object}
|
||||
*/
|
||||
* @property {object} _sounds - Sound key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._sounds = {};
|
||||
|
||||
/**
|
||||
* Text key-value container.
|
||||
* @type {object}
|
||||
*/
|
||||
* @property {object} _text - Text key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._text = {};
|
||||
|
||||
/**
|
||||
* Tilemap key-value container.
|
||||
* @type {object}
|
||||
*/
|
||||
* @property {object} _tilemaps - Tilemap key-value container.
|
||||
* @private
|
||||
*/
|
||||
this._tilemaps = {};
|
||||
|
||||
|
||||
this.addDefaultImage();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onSoundUnlock - Description.
|
||||
*/
|
||||
this.onSoundUnlock = new Phaser.Signal;
|
||||
|
||||
};
|
||||
@@ -63,9 +71,9 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new canvas.
|
||||
* @param key {string} Asset key for this canvas.
|
||||
* @param canvas {HTMLCanvasElement} Canvas DOM element.
|
||||
* @param context {CanvasRenderingContext2D} Render context of this canvas.
|
||||
* @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) {
|
||||
|
||||
@@ -88,12 +96,12 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new sprite sheet.
|
||||
* @param key {string} Asset key for the sprite sheet.
|
||||
* @param url {string} URL of this sprite sheet file.
|
||||
* @param data {object} Extra sprite sheet data.
|
||||
* @param frameWidth {number} Width of the sprite sheet.
|
||||
* @param frameHeight {number} Height of the sprite sheet.
|
||||
* @param frameMax {number} How many frames stored in the sprite sheet.
|
||||
* @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.
|
||||
*/
|
||||
addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) {
|
||||
|
||||
@@ -108,10 +116,10 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new tilemap.
|
||||
* @param key {string} Asset key for the texture atlas.
|
||||
* @param url {string} URL of this texture atlas file.
|
||||
* @param data {object} Extra texture atlas data.
|
||||
* @param atlasData {object} Texture atlas frames data.
|
||||
* @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.
|
||||
*/
|
||||
addTilemap: function (key, url, data, mapData, format) {
|
||||
|
||||
@@ -124,10 +132,11 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new texture atlas.
|
||||
* @param key {string} Asset key for the texture atlas.
|
||||
* @param url {string} URL of this texture atlas file.
|
||||
* @param data {object} Extra texture atlas data.
|
||||
* @param atlasData {object} Texture atlas frames data.
|
||||
* @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.
|
||||
*/
|
||||
addTextureAtlas: function (key, url, data, atlasData, format) {
|
||||
|
||||
@@ -153,9 +162,9 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new Bitmap Font.
|
||||
* @param key {string} Asset key for the font texture.
|
||||
* @param url {string} URL of this font xml file.
|
||||
* @param data {object} Extra font data.
|
||||
* @param {string} key - Asset key for the font texture.
|
||||
* @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) {
|
||||
@@ -173,6 +182,7 @@ Phaser.Cache.prototype = {
|
||||
/**
|
||||
* Adds a default image to be used when a key is wrong / missing.
|
||||
* Is mapped to the key __default
|
||||
* @method addDefaultImage
|
||||
*/
|
||||
addDefaultImage: function () {
|
||||
|
||||
@@ -191,9 +201,10 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new image.
|
||||
* @param key {string} Asset key for the image.
|
||||
* @param url {string} URL of this image file.
|
||||
* @param data {object} Extra image data.
|
||||
* @method addImage
|
||||
* @param {string} key - Asset key for the image.
|
||||
* @param {string} url - URL of this image file.
|
||||
* @param {object} data - Extra image data.
|
||||
*/
|
||||
addImage: function (key, url, data) {
|
||||
|
||||
@@ -207,9 +218,10 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new sound.
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param url {string} URL of this sound file.
|
||||
* @param data {object} Extra sound data.
|
||||
* @method addSound
|
||||
* @param {string} key - Asset key for the sound.
|
||||
* @param {string} url - URL of this sound file.
|
||||
* @param {object} data - Extra sound data.
|
||||
*/
|
||||
addSound: function (key, url, data, webAudio, audioTag) {
|
||||
|
||||
@@ -228,6 +240,11 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload a sound.
|
||||
* @method reloadSound
|
||||
* @param {string} key - Asset key for the sound.
|
||||
*/
|
||||
reloadSound: function (key) {
|
||||
|
||||
var _this = this;
|
||||
@@ -244,6 +261,11 @@ Phaser.Cache.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method reloadSoundComplete
|
||||
* @param {string} key - Asset key for the sound.
|
||||
*/
|
||||
reloadSoundComplete: function (key) {
|
||||
|
||||
if (this._sounds[key])
|
||||
@@ -254,6 +276,11 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method updateSound
|
||||
* @param {string} key - Asset key for the sound.
|
||||
*/
|
||||
updateSound: function (key, property, value) {
|
||||
|
||||
if (this._sounds[key])
|
||||
@@ -265,8 +292,8 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new decoded sound.
|
||||
* @param key {string} Asset key for the sound.
|
||||
* @param data {object} Extra sound data.
|
||||
* @param {string} key - Asset key for the sound.
|
||||
* @param {object} data - Extra sound data.
|
||||
*/
|
||||
decodedSound: function (key, data) {
|
||||
|
||||
@@ -278,9 +305,9 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new text data.
|
||||
* @param key {string} Asset key for the text data.
|
||||
* @param url {string} URL of this text data file.
|
||||
* @param data {object} Extra text data.
|
||||
* @param {string} key - Asset key for the text data.
|
||||
* @param {string} url - URL of this text data file.
|
||||
* @param {object} data - Extra text data.
|
||||
*/
|
||||
addText: function (key, url, data) {
|
||||
|
||||
@@ -293,7 +320,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get canvas by key.
|
||||
* @param key Asset key of the canvas you want.
|
||||
* @param {string} key - Asset key of the canvas you want.
|
||||
* @return {object} The canvas you want.
|
||||
*/
|
||||
getCanvas: function (key) {
|
||||
@@ -308,8 +335,8 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Checks if an image key exists.
|
||||
* @param key Asset key of the image you want.
|
||||
* @return {boolean} True if the key exists, otherwise false.
|
||||
* @param {string} key - Asset key of the image you want.
|
||||
* @return {bool} True if the key exists, otherwise false.
|
||||
*/
|
||||
checkImageKey: function (key) {
|
||||
|
||||
@@ -324,7 +351,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get image data by key.
|
||||
* @param key Asset key of the image you want.
|
||||
* @param {string} key - Asset key of the image you want.
|
||||
* @return {object} The image data you want.
|
||||
*/
|
||||
getImage: function (key) {
|
||||
@@ -339,7 +366,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get tilemap data by key.
|
||||
* @param key Asset key of the tilemap you want.
|
||||
* @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.
|
||||
*/
|
||||
getTilemap: function (key) {
|
||||
@@ -354,7 +381,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get frame data by key.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @param {string} key - Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrameData: function (key) {
|
||||
@@ -369,7 +396,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get a single frame out of a frameData set by key.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @param {string} key - Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrameByIndex: function (key, frame) {
|
||||
@@ -384,7 +411,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get a single frame out of a frameData set by key.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @param {string} key - Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrameByName: function (key, frame) {
|
||||
@@ -399,7 +426,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @param {string} key - Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getFrame: function (key) {
|
||||
@@ -414,7 +441,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image.
|
||||
* @param key Asset key of the frame data you want.
|
||||
* @param {string} key - Asset key of the frame data you want.
|
||||
* @return {object} The frame data you want.
|
||||
*/
|
||||
getTextureFrame: function (key) {
|
||||
@@ -429,7 +456,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get a RenderTexture by key.
|
||||
* @param key Asset key of the RenderTexture you want.
|
||||
* @param {string} key - Asset key of the RenderTexture you want.
|
||||
* @return {object} The RenderTexture you want.
|
||||
*/
|
||||
getTexture: function (key) {
|
||||
@@ -445,7 +472,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get sound by key.
|
||||
* @param key Asset key of the sound you want.
|
||||
* @param {string} key - Asset key of the sound you want.
|
||||
* @return {object} The sound you want.
|
||||
*/
|
||||
getSound: function (key) {
|
||||
@@ -461,7 +488,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get sound data by key.
|
||||
* @param key Asset key of the sound you want.
|
||||
* @param {string} key - Asset key of the sound you want.
|
||||
* @return {object} The sound data you want.
|
||||
*/
|
||||
getSoundData: function (key) {
|
||||
@@ -477,7 +504,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Check whether an asset is decoded sound.
|
||||
* @param key Asset key of the sound you want.
|
||||
* @param {string} key - Asset key of the sound you want.
|
||||
* @return {object} The sound data you want.
|
||||
*/
|
||||
isSoundDecoded: function (key) {
|
||||
@@ -491,7 +518,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Check whether an asset is decoded sound.
|
||||
* @param key Asset key of the sound you want.
|
||||
* @param {string} key - Asset key of the sound you want.
|
||||
* @return {object} The sound data you want.
|
||||
*/
|
||||
isSoundReady: function (key) {
|
||||
@@ -502,7 +529,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Check whether an asset is sprite sheet.
|
||||
* @param key Asset key of the sprite sheet you want.
|
||||
* @param {string} key - Asset key of the sprite sheet you want.
|
||||
* @return {object} The sprite sheet data you want.
|
||||
*/
|
||||
isSpriteSheet: function (key) {
|
||||
@@ -518,7 +545,7 @@ Phaser.Cache.prototype = {
|
||||
|
||||
/**
|
||||
* Get text data by key.
|
||||
* @param key Asset key of the text data you want.
|
||||
* @param {string} key - Asset key of the text data you want.
|
||||
* @return {object} The text data you want.
|
||||
*/
|
||||
getText: function (key) {
|
||||
@@ -572,24 +599,41 @@ Phaser.Cache.prototype = {
|
||||
return this.getKeys(this._text);
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method removeCanvas
|
||||
*/
|
||||
removeCanvas: function (key) {
|
||||
delete this._canvases[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method removeImage
|
||||
*/
|
||||
removeImage: function (key) {
|
||||
delete this._images[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method removeSound
|
||||
*/
|
||||
removeSound: function (key) {
|
||||
delete this._sounds[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method removeText
|
||||
*/
|
||||
removeText: function (key) {
|
||||
delete this._text[key];
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean up cache memory.
|
||||
* @method destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
|
||||
+160
-71
@@ -1,71 +1,86 @@
|
||||
/**
|
||||
* Phaser.Loader
|
||||
*
|
||||
* @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.Loader
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser loader constructor.
|
||||
* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
|
||||
* It uses a combination of Image() loading and xhr and provides progress and completion callbacks.
|
||||
* @class Phaser.Loader
|
||||
* @classdesc The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
|
||||
* It uses a combination of Image() loading and xhr and provides progress and completion callbacks.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Loader = function (game) {
|
||||
|
||||
/**
|
||||
* Local reference to Game.
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Array stores assets keys. So you can get that asset by its unique key.
|
||||
*/
|
||||
* @property {array} _keys - Array stores assets keys. So you can get that asset by its unique key.
|
||||
* @private
|
||||
*/
|
||||
this._keys = [];
|
||||
|
||||
/**
|
||||
* Contains all the assets file infos.
|
||||
*/
|
||||
* @property {Description} _fileList - Contains all the assets file infos.
|
||||
* @private
|
||||
*/
|
||||
this._fileList = {};
|
||||
|
||||
/**
|
||||
* Indicates assets loading progress. (from 0 to 100)
|
||||
* @type {number}
|
||||
* @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100)
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._progressChunk = 0;
|
||||
|
||||
/**
|
||||
* An XMLHttpRequest object used for loading text and audio data
|
||||
* @type {XMLHttpRequest}
|
||||
* @property {XMLHttpRequest} - An XMLHttpRequest object used for loading text and audio data.
|
||||
* @private
|
||||
*/
|
||||
this._xhr = new XMLHttpRequest();
|
||||
|
||||
/**
|
||||
* Length of assets queue.
|
||||
* @type {number}
|
||||
/**
|
||||
* @property {number} - Length of assets queue.
|
||||
* @default
|
||||
*/
|
||||
this.queueSize = 0;
|
||||
|
||||
/**
|
||||
* True if the Loader is in the process of loading the queue.
|
||||
* @type {bool}
|
||||
* @property {bool} isLoading - True if the Loader is in the process of loading the queue.
|
||||
* @default
|
||||
*/
|
||||
this.isLoading = false;
|
||||
|
||||
/**
|
||||
* True if all assets in the queue have finished loading.
|
||||
* @type {bool}
|
||||
* @property {bool} hasLoaded - True if all assets in the queue have finished loading.
|
||||
* @default
|
||||
*/
|
||||
this.hasLoaded = false;
|
||||
|
||||
/**
|
||||
* The Load progress percentage value (from 0 to 100)
|
||||
* @type {number}
|
||||
* @property {number} progress - The Load progress percentage value (from 0 to 100)
|
||||
* @default
|
||||
*/
|
||||
this.progress = 0;
|
||||
|
||||
/**
|
||||
* You can optionally link a sprite to the preloader.
|
||||
* If you do so the Sprite's width or height will be cropped based on the percentage loaded.
|
||||
* @property {Description} preloadSprite
|
||||
* @default
|
||||
*/
|
||||
this.preloadSprite = null;
|
||||
|
||||
/**
|
||||
* The crossOrigin value applied to loaded images
|
||||
* @type {string}
|
||||
* @property {string} crossOrigin - The crossOrigin value applied to loaded images
|
||||
*/
|
||||
this.crossOrigin = '';
|
||||
|
||||
@@ -73,16 +88,29 @@ Phaser.Loader = function (game) {
|
||||
* If you want to append a URL before the path of any asset you can set this here.
|
||||
* Useful if you need to allow an asset url to be configured outside of the game code.
|
||||
* MUST have / on the end of it!
|
||||
* @type {string}
|
||||
* @property {string} baseURL
|
||||
* @default
|
||||
*/
|
||||
this.baseURL = '';
|
||||
|
||||
/**
|
||||
* Event Signals
|
||||
*/
|
||||
* @property {Phaser.Signal} onFileComplete - Event signal.
|
||||
*/
|
||||
this.onFileComplete = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onFileError - Event signal.
|
||||
*/
|
||||
this.onFileError = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onLoadStart - Event signal.
|
||||
*/
|
||||
this.onLoadStart = new Phaser.Signal;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onLoadComplete - Event signal.
|
||||
*/
|
||||
this.onLoadComplete = new Phaser.Signal;
|
||||
|
||||
};
|
||||
@@ -95,7 +123,13 @@ Phaser.Loader.TEXTURE_ATLAS_JSON_HASH = 1;
|
||||
Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2;
|
||||
|
||||
Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
*
|
||||
* @method setPreloadSprite
|
||||
* @param {Phaser.Sprite} sprite - Description.
|
||||
* @param {number} direction - Description.
|
||||
*/
|
||||
setPreloadSprite: function (sprite, direction) {
|
||||
|
||||
direction = direction || 0;
|
||||
@@ -119,7 +153,8 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Check whether asset exists with a specific key.
|
||||
* @param key {string} Key of the asset you want to check.
|
||||
* @method checkKeyExists
|
||||
* @param {string} key - Key of the asset you want to check.
|
||||
* @return {bool} Return true if exists, otherwise return false.
|
||||
*/
|
||||
checkKeyExists: function (key) {
|
||||
@@ -136,8 +171,9 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset loader, this will remove all loaded assets.
|
||||
*/
|
||||
* Reset loader, this will remove all loaded assets.
|
||||
* @method reset
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
this.preloadSprite = null;
|
||||
@@ -148,6 +184,11 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Internal function that adds a new entry to the file list.
|
||||
* @method addToFileList
|
||||
* @param {Description} type - Description.
|
||||
* @param {string} key - Description.
|
||||
* @param {string} url - URL of Description.
|
||||
* @param {Description} properties - Description.
|
||||
*/
|
||||
addToFileList: function (type, key, url, properties) {
|
||||
|
||||
@@ -178,9 +219,10 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add an image to the Loader.
|
||||
* @param key {string} Unique asset key of this image file.
|
||||
* @param url {string} URL of image file.
|
||||
* @param overwrite {boolean} If an entry with a matching key already exists this will over-write it
|
||||
* @method image
|
||||
* @param {string} key - Unique asset key of this image file.
|
||||
* @param {string} url - URL of image file.
|
||||
* @param {boolean} overwrite - If an entry with a matching key already exists this will over-write it
|
||||
*/
|
||||
image: function (key, url, overwrite) {
|
||||
|
||||
@@ -195,8 +237,10 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a text file to the Loader.
|
||||
* @param key {string} Unique asset key of the text file.
|
||||
* @param url {string} URL of the text file.
|
||||
* @method text
|
||||
* @param {string} key - Unique asset key of the text file.
|
||||
* @param {string} url - URL of the text file.
|
||||
* @param {bool} overwrite - True if Description.
|
||||
*/
|
||||
text: function (key, url, overwrite) {
|
||||
|
||||
@@ -211,11 +255,12 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new sprite sheet loading request.
|
||||
* @param key {string} Unique asset key of the sheet file.
|
||||
* @param url {string} URL of sheet file.
|
||||
* @param frameWidth {number} Width of each single frame.
|
||||
* @param frameHeight {number} Height of each single frame.
|
||||
* @param frameMax {number} How many frames in this sprite sheet.
|
||||
* @method spritesheet
|
||||
* @param {string} key - Unique asset key of the sheet file.
|
||||
* @param {string} url - URL of the sheet file.
|
||||
* @param {number} frameWidth - Width of each single frame.
|
||||
* @param {number} frameHeight - Height of each single frame.
|
||||
* @param {number} frameMax - How many frames in this sprite sheet.
|
||||
*/
|
||||
spritesheet: function (key, url, frameWidth, frameHeight, frameMax) {
|
||||
|
||||
@@ -230,9 +275,10 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new audio file loading request.
|
||||
* @param key {string} Unique asset key of the audio file.
|
||||
* @param urls {Array} An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ]
|
||||
* @param autoDecode {bool} When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
|
||||
* @method audio
|
||||
* @param {string} key - Unique asset key of the audio file.
|
||||
* @param {Array} urls - An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ].
|
||||
* @param {bool} autoDecode - When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process.
|
||||
*/
|
||||
audio: function (key, urls, autoDecode) {
|
||||
|
||||
@@ -247,11 +293,12 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new tilemap loading request.
|
||||
* @param key {string} Unique asset key of the tilemap data.
|
||||
* @param tilesetURL {string} The url of the tile set image file.
|
||||
* @param [mapDataURL] {string} The url of the map data file (csv/json)
|
||||
* @param [mapData] {object} An optional JSON data object (can be given in place of a URL).
|
||||
* @param [format] {string} The format of the map data.
|
||||
* @method tilemap
|
||||
* @param {string} key - Unique asset key of the tilemap data.
|
||||
* @param {string} tilesetURL - The url of the tile set image file.
|
||||
* @param {string} [mapDataURL] - The url of the map data file (csv/json)
|
||||
* @param {object} [mapData] - An optional JSON data object (can be given in place of a URL).
|
||||
* @param {string} [format] - The format of the map data.
|
||||
*/
|
||||
tilemap: function (key, tilesetURL, mapDataURL, mapData, format) {
|
||||
|
||||
@@ -293,10 +340,11 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new bitmap font loading request.
|
||||
* @param key {string} Unique asset key of the bitmap font.
|
||||
* @param textureURL {string} The url of the font image file.
|
||||
* @param [xmlURL] {string} The url of the font data file (xml/fnt)
|
||||
* @param [xmlData] {object} An optional XML data object.
|
||||
* @method bitmapFont
|
||||
* @param {string} key - Unique asset key of the bitmap font.
|
||||
* @param {string} textureURL - The url of the font image file.
|
||||
* @param {string} [xmlURL] - The url of the font data file (xml/fnt)
|
||||
* @param {object} [xmlData] - An optional XML data object.
|
||||
*/
|
||||
bitmapFont: function (key, textureURL, xmlURL, xmlData) {
|
||||
|
||||
@@ -349,18 +397,39 @@ Phaser.Loader.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method atlasJSONArray
|
||||
* @param {string} key - Unique asset key of the bitmap font.
|
||||
* @param {Description} atlasURL - The url of the Description.
|
||||
* @param {Description} atlasData - Description.
|
||||
*/
|
||||
atlasJSONArray: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
||||
this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method atlasJSONHash
|
||||
* @param {string} key - Unique asset key of the bitmap font.
|
||||
* @param {Description} atlasURL - The url of the Description.
|
||||
* @param {Description} atlasData - Description.
|
||||
*/
|
||||
atlasJSONHash: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
||||
this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method atlasXML
|
||||
* @param {string} key - Unique asset key of the bitmap font.
|
||||
* @param {Description} atlasURL - The url of the Description.
|
||||
* @param {Description} atlasData - Description.
|
||||
*/
|
||||
atlasXML: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
||||
this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING);
|
||||
@@ -369,11 +438,12 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Add a new texture atlas loading request.
|
||||
* @param key {string} Unique asset key of the texture atlas file.
|
||||
* @param textureURL {string} The url of the texture atlas image file.
|
||||
* @param [atlasURL] {string} The url of the texture atlas data file (json/xml)
|
||||
* @param [atlasData] {object} A JSON or XML data object.
|
||||
* @param [format] {number} A value describing the format of the data.
|
||||
* @method atlas
|
||||
* @param {string} key - Unique asset key of the texture atlas file.
|
||||
* @param {string} textureURL - The url of the texture atlas image file.
|
||||
* @param {string} [atlasURL] - The url of the texture atlas data file (json/xml)
|
||||
* @param {object} [atlasData] - A JSON or XML data object.
|
||||
* @param {number} [format] - A value describing the format of the data.
|
||||
*/
|
||||
atlas: function (key, textureURL, atlasURL, atlasData, format) {
|
||||
|
||||
@@ -448,6 +518,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Remove loading request of a file.
|
||||
* @method removeFile
|
||||
* @param key {string} Key of the file you want to remove.
|
||||
*/
|
||||
removeFile: function (key) {
|
||||
@@ -458,6 +529,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Remove all file loading requests.
|
||||
* @method removeAll
|
||||
*/
|
||||
removeAll: function () {
|
||||
|
||||
@@ -467,6 +539,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Load assets.
|
||||
* @method start
|
||||
*/
|
||||
start: function () {
|
||||
|
||||
@@ -497,6 +570,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
/**
|
||||
* Load files. Private method ONLY used by loader.
|
||||
* @method loadFile
|
||||
* @private
|
||||
*/
|
||||
loadFile: function () {
|
||||
@@ -589,6 +663,11 @@ Phaser.Loader.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Load files. Private method ONLY used by loader.
|
||||
* @method getAudioURL
|
||||
* @param {Description} urls - Description.
|
||||
*/
|
||||
getAudioURL: function (urls) {
|
||||
|
||||
var extension;
|
||||
@@ -610,9 +689,10 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Error occured when load a file.
|
||||
* @param key {string} Key of the error loading file.
|
||||
*/
|
||||
* Error occured when load a file.
|
||||
* @method fileError
|
||||
* @param {string} key - Key of the error loading file.
|
||||
*/
|
||||
fileError: function (key) {
|
||||
|
||||
this._fileList[key].loaded = true;
|
||||
@@ -627,9 +707,10 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when a file is successfully loaded.
|
||||
* @param key {string} Key of the successfully loaded file.
|
||||
*/
|
||||
* Called when a file is successfully loaded.
|
||||
* @method fileComplete
|
||||
* @param {string} key - Key of the successfully loaded file.
|
||||
*/
|
||||
fileComplete: function (key) {
|
||||
|
||||
if (!this._fileList[key])
|
||||
@@ -790,9 +871,10 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Successfully loaded a JSON file.
|
||||
* @param key {string} Key of the loaded JSON file.
|
||||
*/
|
||||
* Successfully loaded a JSON file.
|
||||
* @method jsonLoadComplete
|
||||
* @param {string} key - Key of the loaded JSON file.
|
||||
*/
|
||||
jsonLoadComplete: function (key) {
|
||||
|
||||
var data = JSON.parse(this._xhr.response);
|
||||
@@ -812,9 +894,10 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Successfully loaded a CSV file.
|
||||
* @param key {string} Key of the loaded CSV file.
|
||||
*/
|
||||
* Successfully loaded a CSV file.
|
||||
* @method csvLoadComplete
|
||||
* @param {string} key - Key of the loaded CSV file.
|
||||
*/
|
||||
csvLoadComplete: function (key) {
|
||||
|
||||
var data = this._xhr.response;
|
||||
@@ -827,9 +910,10 @@ Phaser.Loader.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Error occured when load a JSON.
|
||||
* @param key {string} Key of the error loading JSON file.
|
||||
*/
|
||||
* Error occured when load a JSON.
|
||||
* @method dataLoadError
|
||||
* @param {string} key - Key of the error loading JSON file.
|
||||
*/
|
||||
dataLoadError: function (key) {
|
||||
|
||||
var file = this._fileList[key];
|
||||
@@ -842,6 +926,11 @@ Phaser.Loader.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Successfully loaded an XML file.
|
||||
* @method xmlLoadComplete
|
||||
* @param {string} key - Key of the loaded XML file.
|
||||
*/
|
||||
xmlLoadComplete: function (key) {
|
||||
|
||||
var data = this._xhr.response;
|
||||
|
||||
+14
-1
@@ -1,8 +1,21 @@
|
||||
/**
|
||||
* @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.Parser
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Description of Phaser.Loader.Parser
|
||||
*
|
||||
* @class Phaser.Loader.Parser
|
||||
*/
|
||||
Phaser.Loader.Parser = {
|
||||
|
||||
/**
|
||||
* Parse frame data from an XML file.
|
||||
* @param xml {object} XML data you want to parse.
|
||||
* @param {object} xml - XML data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
bitmapFont: function (game, xml, cacheKey) {
|
||||
|
||||
Reference in New Issue
Block a user