From 32253672406de5c84c4a6bc4f3afa6cd40d75d3e Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 9 Feb 2018 15:22:55 +0000 Subject: [PATCH] Check for new TP3 structure. --- src/textures/TextureManager.js | 5 ++--- src/textures/parsers/JSONArray.js | 14 +++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/textures/TextureManager.js b/src/textures/TextureManager.js index 91bbf94e4..190f3464d 100644 --- a/src/textures/TextureManager.js +++ b/src/textures/TextureManager.js @@ -277,9 +277,8 @@ var TextureManager = new Class({ */ addAtlas: function (key, source, data) { - // Is it a Hash or an Array? - - if (Array.isArray(data.frames)) + // New Texture Packer format? + if (Array.isArray(data.textures) || Array.isArray(data.frames)) { return this.addAtlasJSONArray(key, source, data); } diff --git a/src/textures/parsers/JSONArray.js b/src/textures/parsers/JSONArray.js index 824f21488..ed13cb757 100644 --- a/src/textures/parsers/JSONArray.js +++ b/src/textures/parsers/JSONArray.js @@ -16,9 +16,9 @@ var Clone = require('../../utils/object/Clone'); var JSONArray = function (texture, sourceIndex, json) { // Malformed? - if (!json['frames']) + if (!json['frames'] && !json['textures']) { - console.warn('Invalid Texture Atlas JSON Array given, missing \'frames\' array'); + console.warn('Invalid Texture Atlas JSON Array given, missing \'frames\' and \'textures\' array'); return; } @@ -28,7 +28,8 @@ var JSONArray = function (texture, sourceIndex, json) texture.add('__BASE', sourceIndex, 0, 0, source.width, source.height); // By this stage frames is a fully parsed array - var frames = json['frames']; + var frames = (Array.isArray(json.textures)) ? json.textures[0].frames : json.frames; + var newFrame; for (var i = 0; i < frames.length; i++) @@ -57,6 +58,13 @@ var JSONArray = function (texture, sourceIndex, json) newFrame.updateUVsInverted(); } + if (src.anchor) + { + newFrame.customPivot = true; + newFrame.pivotX = src.anchor.x; + newFrame.pivotY = src.anchor.y; + } + // Copy over any extra data newFrame.customData = Clone(src); }