Tilemap load as JSON not working

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I'm trying to load the tilemap as a JSON string into a variable through something like

    replace(TilemapsGround.AsJSON, "x6,", "x7,")

    to do tile animations without needing to do a CPU-intensive 400x for loop to do tile animations with a tilemap. The problem is, after I load the tilemap as a JSON string into a variable, it will not accept the variable as a JSON string when I tell the tilemap to load from a JSON string. Am I doing something wrong?

    EDIT: Screenshot of what I'm doing. Testvari was to test if the tilemap JSON string is changed, which it doesn't, so Testvari keeps adding 1 forever.

    https://drive.google.com/file/d/0Bz86oQ ... sp=sharing

  • Nevermind, I thought pulling the tilemap as a JSON string would give me the same output as if I had the file download as a JSON, but apparently both are way different, so I basically had to rebuild the JSON string the tilemap gave me, by putting this:

    "{""c2tilemap"":true,""width"":" & TilemapsGround.Width / 16 & ",""height"":" & TilemapsGround.Height / 16 & ",""data"":" & replace(replace(replace(replace(tokenat(TilemapsGround.AsJSON, tokencount(TilemapsGround.AsJSON, ":") - 1, ":"), "x" & Function.Param(1) & ",", "x" & Function.Param(2) & ","), "," & Function.Param(1) & ",", "," & Function.Param(2) & ","), "x" & Function.Param(1) & """", "x" & Function.Param(2) & """"), "," & Function.Param(1) & """", "," & Function.Param(2) & """")

    This is WAAAY faster than having your game for loop through every single tile, so I suggest anyone reading this uses this approach.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Still not as fast as ... if you can do it with Tile > Set tile range.

    But thanks for the JSON string.

  • Probably not, but doesn't "set tile range" only turn all the tiles in a square into the same tile? This changes all the instances of a specific tile on an entire tilemap into a new one.

  • Yesh ! Or two squares, or 3. Saw you wanted to animate the tilemap, wich is btw a very good idea, if you ask me.

    If have not idea if you can do it in a 'range'. Just suggested it.

  • Yeah I do my stages with multiple tilemaps to define scrolling regions, and I have like 30 320x240 screens worth of them, and I can animate them all at once and it doesn't seem to even effect the FPS. I still make it only animate the current one you're standing on though, just to lighten CPU load a little.

    The reason it needs multiple replace expressions is because there are instances where you'll have like x7, ,7, ,7" due to how the tilemaps are stored as JSON strings, and if you just make it change 7, that's going to also change 17, 27, etc.

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