friedmr5 Posted June 13, 2017 Share Posted June 13, 2017 Hi all, I'm new to development in general and definitely new to Phaser, and I have run into an issue I haven't seen mentioned elsewhere. I had followed a tutorial from Discover Phaser to create my first game. The tilemap was created using Tiled and exported as a JSON file. In order to get the tutorial game to run, I needed to edit the data in the JSON file. I'm using Brackets to edit my code and have not touched the minified framework file. I am now building my own simple game with a small tilemap (12x12), and have exported a JSON file. However, whether I leave the JSON file as is, or I edit it so that its structure is identical to what worked in Discover Phaser's tutorial, my game still crashes when it tries to load the map. The errors I get look like this: Quote Uncaught TypeError: Cannot read property '2' of undefined at Object.parseTiledJSON (phaser.min.js:26) at Object.parse (phaser.min.js:26) at new c.Tilemap (phaser.min.js:25) at c.GameObjectFactory.tilemap (phaser.min.js:15) at Object.createWorld (play.js:289) at Object.create (play.js:25) at c.StateManager.loadComplete (phaser.min.js:10) at c.StateManager.preUpdate (phaser.min.js:10) at c.Game.updateLogic (phaser.min.js:12) at c.Game.update (phaser.min.js:12) When I try exporting the map as a CSV file, the game no longer freezes, but the map still doesn't load. The only error that shows is this one, from the 25th line of the phaser.min.js file: Quote Tilemap.createLayer: Invalid layer ID given: null There are a few things I don't know. What any of these errors mean in terms of trying to load the tilemap Why I'm getting these errors What Phaser is expecting to come out of these files. What is it reading? If anyone could shed some light on this, I'd be eternally grateful. Link to comment Share on other sites More sharing options...
Skeptron Posted June 15, 2017 Share Posted June 15, 2017 It's really hard to help you with such few information, but I'd say it's related to the layers in your map. Make sure the layers you have declared in your Tiled file and the ones you use in the code are identical. Link to comment Share on other sites More sharing options...
samme Posted June 15, 2017 Share Posted June 15, 2017 The first error means Phaser failed to read/interpret the exported map. That step should succeed for a typical map exported from Tiled, so the most likely cause is that editing the map file by hand spoiled it. The second error means Phaser couldn't find the layer named in the createLayer call. Link to comment Share on other sites More sharing options...
friedmr5 Posted June 16, 2017 Author Share Posted June 16, 2017 Hi Samme, Thank you for your reply. I agree, editing the map by hand probably did spoil it. Tiled wouldn't even reopen the JSON files that I touched. What I don't understand is why these errors don't go away when I leave the file in its default state. I will make sure to double check all of my layer names, etc, as Skeptron has suggested. Will update this thread when I go back and test it again. Link to comment Share on other sites More sharing options...
nimohe Posted June 20, 2017 Share Posted June 20, 2017 (edited) On 2017/6/17 at 2:18 AM, fpg246 said: Hi Samme, Thank you for your reply. I agree, editing the map by hand probably did spoil it. Tiled wouldn't even reopen the JSON files that I touched. What I don't understand is why these errors don't go away when I leave the file in its default state. I will make sure to double check all of my layer names, etc, as Skeptron has suggested. Will update this thread when I go back and test it again. hi,fpg246 you need use this old ver 0.18.2 down link : https://github.com/bjorn/tiled/releases/tag/v0.18.2 today I updated TiledMap to ver-1.0.1,export json file,the errors has show. so I decided to use old ver,and then the code run ok. tip:just export JSON,not CSV hope can help you ? Edited June 20, 2017 by nimohe add tip Link to comment Share on other sites More sharing options...
samme Posted June 20, 2017 Share Posted June 20, 2017 @nimohe can you post a v1.0.1 JSON file that causes the error? Link to comment Share on other sites More sharing options...
nimohe Posted June 21, 2017 Share Posted June 21, 2017 11 hours ago, samme said: @nimohe can you post a v1.0.1 JSON file that causes the error? hi samme,look here. https://github.com/nimohe/test-Tiledmapeditor-export-JSON-with-Phaser samme 1 Link to comment Share on other sites More sharing options...
samme Posted June 21, 2017 Share Posted June 21, 2017 So the problem is the new external tileset (.tsx) feature in Tiled v1.0.0. You need to use either the Import Tileset button or Map → Add External Tileset, I'm not sure which. Link to comment Share on other sites More sharing options...
nimohe Posted June 22, 2017 Share Posted June 22, 2017 10 hours ago, samme said: So the problem is the new external tileset (.tsx) feature in Tiled v1.0.0. You need to use either the Import Tileset button or Map → Add External Tileset, I'm not sure which. solved !!! I updated my github :https://github.com/nimohe/test-Tiledmapeditor-export-JSON-with-Phaser solved way: need to click 'Embed Tileset' button -->then export JSON --> run code will be ok samme 1 Link to comment Share on other sites More sharing options...
samme Posted June 22, 2017 Share Posted June 22, 2017 @fpg246 try Embed Tileset. Link to comment Share on other sites More sharing options...
friedmr5 Posted June 23, 2017 Author Share Posted June 23, 2017 On 6/21/2017 at 0:48 PM, samme said: So the problem is the new external tileset (.tsx) feature in Tiled v1.0.0. You need to use either the Import Tileset button or Map → Add External Tileset, I'm not sure which. This was it!!! Thank you so much! Link to comment Share on other sites More sharing options...
samme Posted July 2, 2017 Share Posted July 2, 2017 phaser-ce/issues/273 Link to comment Share on other sites More sharing options...
Recommended Posts