How do I load a tilemap from json?

0 favourites
  • 13 posts
From the Asset Store
This is a black tileset with 2 tilemaps, props, one animated character and more.
  • Hi, Ideally I want to populate an array with the json data then load from the array into the tilemap. However I can't even get the normal set tilemap from json string working for some reason. I feel like I am missing something very obvious here.

    Here's what I've got so far.

    https://drive.google.com/file/d/10ngzonI0YE0F_-kpZmk4NZ_NdM28KsEk/view?usp=sharing

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • When downloading the file use .TilesJSON and then use the Load action instead of Set.

  • Ah yes that works! Thanks!

    Any idea how to do the same but with the array?

  • Instead of loading ajax.lastdata directly onto the tilemap you can set it in an array and then later on use array.at(x,y)

  • Hmm I get an empty array when I try & load it in :/

    https://drive.google.com/file/d/1xhg3ZJDoGUauRKcfwod8gyhXAcFWny0S/view?usp=sharing

  • This logic doesn't make much sense, what are you trying to do with the array? The load action is for loading pre-existing array data, not tile data. You can set a position in the array to ajax.lastdata and load it later using the tilemap load action.

  • So I'm imagining it puts the tilemap data in the array & each element of the array corresponds to a tile in the tilemap when you load it, or does it not work like that?

    *edit ah I see, is there anyway to do something similar to what I am thinking?

  • No the tilemap data is one string. You can store this string in one position of the array to use later, but the question is do you need to?

  • Well my thinking was I want to randomly generate one large long level a little bit like the way the Binding of Isaac puts random rooms together. So I'd take each room that I've designed & downloaded then put it in an array the size of each room (30x17) then put that into a larger 'level array' one next to each other how ever many times to make the one long level.

    I guess I could always just create multiple tilemaps & use the former method of loading for each room though now that I think about it.

    I'm probably trying to overengineer it & make things way more difficult for myself that need be, my speciality :)

  • You can store all the room layouts in an array yes but you'll come across a problem that the exits don't sync up if you're creating it in advance. Not sure how people would solve that problem. I made something similar when on exiting a room it created a random room during runtime.

  • Yeah I just tested what I suggested & it seems to work no problems, thanks for helping me understand tilemaps & arrays a little better :)

  • You can store all the room layouts in an array yes but you'll come across a problem that the exits don't sync up if you're creating it in advance. Not sure how people would solve that problem. I made something similar when on exiting a room it created a random room during runtime.

    Hmm yeah good point, I've just gone for all the exits & entrances are the same size so line up naturally, but I guess you could take the position of the empty tiles in the first column of the next tilemap & erase the end tiles on the previous to match up? This is for the way I am using the tilemaps, all in a row left to right, no idea for randomly placed ones. Perhaps lining them up based on imagepoints or something.

  • Not referring to the size I mean like in Isaac when you exit from the top and enter the next room from the bottom. You would need extra logic to work all this out so they are aligned. If your game just has a line of rooms going from left to right then it might be fine.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)