Spideynn Posted December 12, 2016 Share Posted December 12, 2016 I've been trying to get tilemaps working properly in Phaser, and found out that for some reason Phaser doesn't load my tilemap properly when I load a multi-layer JSON tilemap that I exported from Tiled. With help from someone on the StackOverflow community (my question is here: http://stackoverflow.com/questions/40813741/trying-to-load-a-tilemap-causes-typeerror) I tested this with a simple tilemap (4x4 w/ 1 layer) and it worked fine. I then tried to load it with a slightly larger, multi-layer tilemap and it threw a console error: I'm not sure if this is a Phaser bug, but after all the troubleshooting I've done I think it might be. My code is on GitHub: https://github.com/spideynn/phaser-tilemaps Link to comment Share on other sites More sharing options...
drhayes Posted December 12, 2016 Share Posted December 12, 2016 Your Tiled JSON file is looking for "tilemap.png": https://github.com/spideynn/phaser-tilemaps/blob/e01cfa377a70d41874658b42f082e32abc0651dd/assets/tilemap/maze.json#L44 Your code is supplying an image for "tiles": https://github.com/spideynn/phaser-tilemaps/blob/e01cfa377a70d41874658b42f082e32abc0651dd/js/Main.js#L15 The first argument to "addTilesetImage" is the name of the tileset in the map data. In other words, "tilemap.png". Try changing that first param you're passing to addTilesetImage to "tilemap.png" and see what happens. Link to comment Share on other sites More sharing options...
Spideynn Posted December 12, 2016 Author Share Posted December 12, 2016 5 minutes ago, drhayes said: Your Tiled JSON file is looking for "tilemap.png": https://github.com/spideynn/phaser-tilemaps/blob/e01cfa377a70d41874658b42f082e32abc0651dd/assets/tilemap/maze.json#L44 Your code is supplying an image for "tiles": https://github.com/spideynn/phaser-tilemaps/blob/e01cfa377a70d41874658b42f082e32abc0651dd/js/Main.js#L15 The first argument to "addTilesetImage" is the name of the tileset in the map data. In other words, "tilemap.png". Try changing that first param you're passing to addTilesetImage to "tilemap.png" and see what happens. I tried changing it and it gave me this warning along with the other error: Phaser.Tilemap.addTilesetImage: No data found in the JSON matching the tileset name: "tilemap.png" Link to comment Share on other sites More sharing options...
drhayes Posted December 12, 2016 Share Posted December 12, 2016 Ack! My mistake! The tileset's name is "tiles", but the image is "tilemap.png". Shoot, I thought I had it! Drat. Your code was right, I was wrong. That error message is what the canvas throws when you call "drawImage" but don't pass it an image. My guess is that something (I can't tell what) in your game is trying to draw itself without a texture. It's *probably* your map, but your code looks fine to me. It looks like you have two layers named "tiles" in your map.json? Maybe that's it? Like, manually remove the second one and see if it works? Link to comment Share on other sites More sharing options...
Spideynn Posted December 12, 2016 Author Share Posted December 12, 2016 I tried removing one and it gave me another error: TypeError: map.tiles[tile.index] is undefined I tried replacing the remaining tileset with the other tileset that I removed and it gave me the same error. Link to comment Share on other sites More sharing options...
drhayes Posted December 13, 2016 Share Posted December 13, 2016 That's probably because you've got tile references in the layers that refer to both tilesets. Did you remove the tilesets in Tiled? It didn't remove those tile references? Shoot. I'm running out of ideas. Link to comment Share on other sites More sharing options...
Spideynn Posted December 13, 2016 Author Share Posted December 13, 2016 1 hour ago, drhayes said: That's probably because you've got tile references in the layers that refer to both tilesets. Did you remove the tilesets in Tiled? It didn't remove those tile references? Shoot. I'm running out of ideas. So I guess when I removed a tileset Tiled didn't remove the tiles from a layer (a tileset was used in two different layers, and it removed it from one but not the other, I ended up remaking the layer) and it seems to be fine now. drhayes 1 Link to comment Share on other sites More sharing options...
drhayes Posted December 14, 2016 Share Posted December 14, 2016 Huzzah! So it's loading your map now? Link to comment Share on other sites More sharing options...
Recommended Posts