From e577d0424067025851550391fe995a831eb994f8 Mon Sep 17 00:00:00 2001 From: Chad Engler Date: Fri, 17 Oct 2014 07:13:53 -0700 Subject: [PATCH] parse animation data in XML, fixes #6 --- src/tiled/TilemapParser.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tiled/TilemapParser.js b/src/tiled/TilemapParser.js index 4e3b61b..62d52c5 100644 --- a/src/tiled/TilemapParser.js +++ b/src/tiled/TilemapParser.js @@ -254,7 +254,7 @@ var TilemapParser = { } } - //add .tiles if multi-image set + //add .tiles if there are tile-specific properties for(var t = 0; t < tiles.length; ++t) { var tile = tiles[t], id = tile.attributes.getNamedItem('id').value, @@ -297,6 +297,22 @@ var TilemapParser = { tileset.tileproperties[id][tileprop.attributes.getNamedItem('name').value] = tileprop.attributes.getNamedItem('value').value; } } + + //add all the tile animations + var tileanims = tile.getElementsByTagName('animation'); + if (tileanims.length) { + tileset.tiles[id].animation = []; + tileanims = tileanims[0].getElementsByTagName('frame'); + for(var tn = 0; tn < tileanims.length; ++tn) { + var tileanim = tileanims[tn].attributes, + animObj = {}; + for (var tna = 0; tna < tileanim.length; ++tna) { + animObj[tileanim[tna].name] = tileanim[tna].value; + } + + tileset.tiles[id].animation.push(animObj); + } + } } //check for terraintypes and add those