Jump to content

Load tileset automatically from JSON file


Recommended Posts

Hi guys! First post here, still getting my feet wet with Phaser, and loving it so far!


I'm trying to port an existing RPG engine I have working on iOS, and I've managed to convert and load my tilemaps from JSON files exported by Tiled. One thing that bothers me though is that in every tilemap sample I've seen the tileset is manually preloaded, separately from the tilemap file.


I'm my case that would be a pain because pretty much every map has its own tileset, and it would be better it there was a way for Phaser to automatically load the tileset from the image specified within the JSON file. I've searched around this forum and the docs, but found nothing like that, is that possible? The only way I can see to do that would be for my own code to "pre-parse" the JSON file and get the name of the image file, but that is inconvenient and defeats the whole concept of Phaser's States preloading the necessary resources (as these map files can get quite large).


Thanks in advance!

Link to comment
Share on other sites

There are two reasons I didn't do this:


1) The main reason was that it allowed you to easily use a variety of tilesets with 1 set of map data, by just swapping the image being used.


2) The image paths in the json are usually a right mess. Sometimes relative, often with local file systems included. Knowing where to actually load it from would have to be pure guess work, I could strip everything other than the filename maybe, but if you've got your images stored in a sub-folder it would break that, and I can't know at what point the path is correct. So I'd have to find a way for you to tell the parser "this bit is correct, this isn't", etc and frankly it's a bit of a mess.


So sorry, but in this instance you need to roll your own solution I'm afraid.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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