Jump to content

Phaser error when using tilemaps with multiple layers


Spideynn
 Share

Recommended Posts

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:

4E7W8.png

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

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

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

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

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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...