Tilemap load as JSON not working

Get help using Construct 2

Post » Tue Aug 02, 2016 2:34 pm

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
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Tue Aug 02, 2016 4:37 pm

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.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Tue Aug 02, 2016 4:51 pm

Still not as fast as ... if you can do it with Tile > Set tile range.

But thanks for the JSON string.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Aug 02, 2016 9:20 pm

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.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010

Post » Tue Aug 02, 2016 10:24 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Aug 03, 2016 9:40 am

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.
B
45
S
13
G
1
Posts: 236
Reputation: 4,010


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Yahoo [Bot] and 29 guests