2016-09-29 15:10:22 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2016 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses a JSON Array and extracts the frame data from it.
|
|
|
|
*
|
|
|
|
* @class Phaser.TextureParser.JSONArray
|
|
|
|
* @static
|
|
|
|
* @param {Phaser.Texture} texture - The parent Texture.
|
|
|
|
* @param {object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format.
|
|
|
|
* @return {Phaser.FrameData} A FrameData object containing the parsed frames.
|
|
|
|
*/
|
2016-10-19 13:29:52 +00:00
|
|
|
Phaser.TextureManager.Parsers.JSONHash = function (texture, sourceIndex, json)
|
2016-09-29 15:10:22 +00:00
|
|
|
{
|
|
|
|
// Malformed?
|
|
|
|
if (!json['frames'])
|
|
|
|
{
|
2016-10-19 13:29:52 +00:00
|
|
|
console.warn('Invalid Texture Atlas JSON Hash given, missing \'frames\' Object');
|
2016-09-29 15:10:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:29:52 +00:00
|
|
|
// By this stage frames is a fully parsed Object
|
2016-09-29 15:10:22 +00:00
|
|
|
var frames = json['frames'];
|
|
|
|
var newFrame;
|
|
|
|
|
|
|
|
for (var key in frames)
|
|
|
|
{
|
|
|
|
var src = frames[key];
|
|
|
|
|
|
|
|
// The frame values are the exact coordinates to cut the frame out of the atlas from
|
2016-10-19 13:29:52 +00:00
|
|
|
newFrame = texture.add(key, sourceIndex, src.frame.x, src.frame.y, src.frame.w, src.frame.h);
|
2016-09-29 15:10:22 +00:00
|
|
|
|
|
|
|
// These are the original (non-trimmed) sprite values
|
|
|
|
if (src.trimmed)
|
|
|
|
{
|
|
|
|
newFrame.setTrim(
|
|
|
|
src.sourceSize.w,
|
|
|
|
src.sourceSize.h,
|
|
|
|
src.spriteSourceSize.x,
|
|
|
|
src.spriteSourceSize.y,
|
|
|
|
src.spriteSourceSize.w,
|
|
|
|
src.spriteSourceSize.h
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src.rotated)
|
|
|
|
{
|
|
|
|
newFrame.rotated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 13:29:52 +00:00
|
|
|
return texture;
|
2016-09-29 15:10:22 +00:00
|
|
|
};
|