mirror of
https://github.com/photonstorm/phaser
synced 2024-12-14 23:32:52 +00:00
Custom JSON loader
Added a method in the Loader that enable the load of custom json files, to be used like a the general settings of the game. loading: game.load.json (key, url); retrieving data from json file: game.cache.getText(key);
This commit is contained in:
parent
c9d07c7346
commit
3236ea6b24
1 changed files with 22 additions and 3 deletions
|
@ -369,6 +369,22 @@ Phaser.Loader.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a custom JSON file to the Loader.
|
||||
*
|
||||
* @method Phaser.Loader#json
|
||||
* @param {string} key - Unique asset key of the json file.
|
||||
* @param {string} url - URL of the json file.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
json: function (key, url) {
|
||||
|
||||
this.addToFileList('json', key, url);
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a binary file to the Loader. It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load.
|
||||
* When the callback is called it will be passed 2 parameters: the key of the file and the file data.
|
||||
|
@ -826,12 +842,12 @@ Phaser.Loader.prototype = {
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'tilemap':
|
||||
case 'json':
|
||||
this._xhr.open("GET", this.baseURL + file.url, true);
|
||||
this._xhr.responseType = "text";
|
||||
|
||||
if (file.format === Phaser.Tilemap.TILED_JSON)
|
||||
if (!file.format || file.format === Phaser.Tilemap.TILED_JSON)
|
||||
{
|
||||
this._xhr.onload = function () {
|
||||
return _this.jsonLoadComplete(_this._fileIndex);
|
||||
|
@ -853,7 +869,6 @@ Phaser.Loader.prototype = {
|
|||
};
|
||||
this._xhr.send();
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
case 'script':
|
||||
this._xhr.open("GET", this.baseURL + file.url, true);
|
||||
|
@ -1112,6 +1127,10 @@ Phaser.Loader.prototype = {
|
|||
{
|
||||
this.game.cache.addTilemap(file.key, file.url, data, file.format);
|
||||
}
|
||||
else if (file.type === 'json')
|
||||
{
|
||||
this.game.cache.addText(file.key, file.url, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.cache.addTextureAtlas(file.key, file.url, file.data, data, file.format);
|
||||
|
|
Loading…
Reference in a new issue