mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
cherry pick commits from master. Read: I'm not clever.
This commit is contained in:
parent
41906c5ac1
commit
cbd7265bee
3 changed files with 76 additions and 1 deletions
|
@ -147,6 +147,65 @@ Phaser.AnimationParser = {
|
|||
/**
|
||||
* Parse the JSON data and extract the animation frame data from it.
|
||||
*
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
* @method Phaser.AnimationParser.JSONData
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in Pyxel JSON format.
|
||||
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
||||
*/
|
||||
JSONDataPyxel: function (game, json) {
|
||||
|
||||
// Malformed? There are a few keys to check here.
|
||||
var signature = ['layers', 'tilewidth','tileheight','tileswide', 'tileshigh'];
|
||||
|
||||
signature.forEach( function(key, index) {
|
||||
if (!json[key])
|
||||
{
|
||||
console.warn("Phaser.AnimationParser.JSONDataPyxel: Invalid Pyxel Tilemap JSON given, missing '" + key + "' key.");
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// For this purpose, I only care about parsing tilemaps with a single layer.
|
||||
if(json['layers'].length != 1) {
|
||||
console.warn("Phaser.AnimationParser.JSONDataPyxel: Too many layers, this parser only supports flat Tilemaps.");
|
||||
console.log(json);
|
||||
return;
|
||||
}
|
||||
|
||||
var data = new Phaser.FrameData();
|
||||
|
||||
var tileheight = json['tileheight'];
|
||||
var tilewidth = json['tilewidth'];
|
||||
|
||||
var frames = json['layers'][0]['tiles'];
|
||||
var newFrame;
|
||||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
newFrame = data.addFrame(new Phaser.Frame(
|
||||
i,
|
||||
frames[i].x,
|
||||
frames[i].y,
|
||||
tilewidth,
|
||||
tileheight,
|
||||
"frame_" + i // No names are included in pyxel tilemap data.
|
||||
));
|
||||
|
||||
// No trim data is included.
|
||||
newFrame.setTrim(false);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse the JSON data and extract the animation frame data from it.
|
||||
*
|
||||
>>>>>>> 247064f... fixed some typos and explicitly setTrim to false
|
||||
* @method Phaser.AnimationParser.JSONDataHash
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
|
||||
|
|
|
@ -604,6 +604,13 @@ Phaser.Cache.prototype = {
|
|||
{
|
||||
obj.frameData = Phaser.AnimationParser.XMLData(this.game, atlasData, key);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
else if (format === Phaser.Loader.TEXTURE_ATLAS_JSON_PYXEL)
|
||||
{
|
||||
obj.frameData = Phaser.AnimationParser.JSONDataPyxel(this.game, atlasData, key);
|
||||
}
|
||||
>>>>>>> 247064f... fixed some typos and explicitly setTrim to false
|
||||
else
|
||||
{
|
||||
// Let's just work it out from the frames array
|
||||
|
|
|
@ -296,6 +296,15 @@ Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2;
|
|||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
Phaser.Loader.TEXTURE_ATLAS_JSON_PYXEL = 3;
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @type {number}
|
||||
*/
|
||||
>>>>>>> 247064f... fixed some typos and explicitly setTrim to false
|
||||
Phaser.Loader.PHYSICS_LIME_CORONA_JSON = 3;
|
||||
|
||||
/**
|
||||
|
@ -2605,7 +2614,7 @@ Phaser.Loader.prototype = {
|
|||
// Load the JSON or XML before carrying on with the next file
|
||||
loadNext = false;
|
||||
|
||||
if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH)
|
||||
if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_PYXEL)
|
||||
{
|
||||
this.xhrLoad(file, this.transformUrl(file.atlasURL, file), 'text', this.jsonLoadComplete);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue