From 22ecd23f0959d31dfa770c3d3a9e340c6476c234 Mon Sep 17 00:00:00 2001 From: Joachim Grill Date: Tue, 27 Feb 2018 14:48:45 +0100 Subject: [PATCH] fixed multiatlas loader to support new TexturePacker atlas format introduced for Phaser 3 --- src/loader/LoaderPlugin.js | 2 +- src/textures/TextureManager.js | 6 ++++-- src/textures/parsers/JSONArray.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/loader/LoaderPlugin.js b/src/loader/LoaderPlugin.js index 159cbd635..448a93d8c 100644 --- a/src/loader/LoaderPlugin.js +++ b/src/loader/LoaderPlugin.js @@ -656,7 +656,7 @@ var LoaderPlugin = new Class({ // Yup, add them to the Texture Manager // Is the data JSON Hash or JSON Array? - if (Array.isArray(data[0].frames)) + if (Array.isArray(data[0].textures) || Array.isArray(data[0].frames)) { textures.addAtlasJSONArray(key, images, data); } diff --git a/src/textures/TextureManager.js b/src/textures/TextureManager.js index 91ad16486..79f53a4d1 100644 --- a/src/textures/TextureManager.js +++ b/src/textures/TextureManager.js @@ -314,9 +314,11 @@ var TextureManager = new Class({ if (Array.isArray(data)) { - for (var i = 0; i < data.length; i++) + var singleAtlasFile = (data.length === 1); // multi-pack with one atlas file for all images + for (var i = 0; i < texture.source.length; i++) { - Parser.JSONArray(texture, i, data[i]); + var atlasData = singleAtlasFile ? data[0] : data[i]; + Parser.JSONArray(texture, i, atlasData); } } else diff --git a/src/textures/parsers/JSONArray.js b/src/textures/parsers/JSONArray.js index e0f22ee60..a6eef5638 100644 --- a/src/textures/parsers/JSONArray.js +++ b/src/textures/parsers/JSONArray.js @@ -34,7 +34,7 @@ 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 = (Array.isArray(json.textures)) ? json.textures[0].frames : json.frames; + var frames = (Array.isArray(json.textures)) ? json.textures[sourceIndex].frames : json.frames; var newFrame;