[SOLVED] Load C2 generated JSON array into Tilemap in Editor

Get help using Construct 2

Post » Tue Dec 08, 2015 11:53 am

Hi all!

I've been working on a level editor, which can save & load levels in runtime in json format. However, today I realized that one can only load tilemap from TMX files in the C2 editor view.

Is there a way to load C2 generated JSON string to populate a tilemap object already in the editor view?
Alternatively, is there a way to export (save) the tilemap as TMX JSON format during runtime in C2 (so that it would be later possible to open in the editor view)?
Last edited by striimix on Tue Dec 15, 2015 11:42 am, edited 1 time in total.
B
14
S
3
G
1
Posts: 78
Reputation: 1,037

Post » Tue Dec 08, 2015 11:59 am

You can put json into array.
action > array > (JSON) Download > input string.
Then you can interpreter the array how you want.
Image
B
23
S
5
G
5
Posts: 143
Reputation: 3,762

Post » Tue Dec 08, 2015 1:09 pm

Rexu wrote:You can put json into array.
action > array > (JSON) Download > input string.
Then you can interpreter the array how you want.

Thanks for your response, but my problem/question is how do you get the tiles to display inside the Construct 2 editor?

I already have loading and saving working perfectly during runtime. What I would like to see, is to load the tiles into the tilemap object already in the editor view of Construct 2 (and not from TMX file but from a json (for example, Tilemap.AsJSON string generated in C2).
B
14
S
3
G
1
Posts: 78
Reputation: 1,037

Post » Tue Dec 08, 2015 4:06 pm

I'm not sure if that's possible. You should seek for a third party plugin or something like this, but even plugins don't work this way. For editing purposes you can print image of your tilemap while in runtime then overlay it in editor.
Image
B
23
S
5
G
5
Posts: 143
Reputation: 3,762

Post » Mon Dec 14, 2015 9:02 pm

Thanks for the suggestion. For my needs it would be important to simply get the tiles loaded on different layouts from the json created by C2 rather than TMX created on Tiled, so that the levels could be expaned with objects etc. The reason why levels are created with C2 made level editor instead of the editor view of Construct2 is because I wanted to have an easy to use editor to create the overall levels and be able to test the gameplay on runtime right away. However, leaving levels as plain as that would make them a bit boring and repetitive in the long run - coding object placements and such on the other hand would make the level editor bloated and not so easy to use.

@Ashley is there any chance of getting possibility of exporting tilemaps in the TMX format in runtime from C2 or alternatively loading tilesheet from JSON already in the editor view of Construct 2 (currently we can only do that during runtime, which works perfectly but sadly the editor does not remember the loaded tilemap in the editor view after testing)
B
14
S
3
G
1
Posts: 78
Reputation: 1,037

Post » Tue Dec 15, 2015 6:39 am

You could do it by manually editing the layout's xml file. Under the tilemap instance there is a block called "tilemap-data" that stores the tilemap's tiles.

Now what the tilemap's tilemap.tilesJSON expression gives is compressed with rle, and the ordering is a bit different.

Here's a utility that you can use to convert it to be usable in the xml.
https://www.dropbox.com/s/w7b6tjsawhdbp ... .capx?dl=1
/examples31/tilesJSON_convert.capx
Last edited by R0J0hound on Mon Sep 11, 2017 10:10 pm, edited 1 time in total.
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779

Post » Tue Dec 15, 2015 11:38 am

Thanks @R0J0hound - that was exactly what I was looking for! Works like a charm now =)
B
14
S
3
G
1
Posts: 78
Reputation: 1,037

Post » Sat Jan 23, 2016 3:55 pm

@R0J0hound - that is simply excellent! Thank you.
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,255
Reputation: 46,484

Post » Wed Aug 30, 2017 7:46 am

R0J0hound wrote:You could do it by manually editing the layout's xml file. Under the tilemap instance there is a block called "tilemap-data" that stores the tilemap's tiles.

Now what the tilemap's tilemap.tilesJSON expression gives is compressed with rle, and the ordering is a bit different.

Here's a utility that you can use to convert it to be usable in the xml.
https://dl.dropboxusercontent.com/u/542 ... nvert.capx


@R0J0hound
Please, you could restore the download link?
B
21
S
5
Posts: 59
Reputation: 1,283

Post » Mon Sep 11, 2017 10:10 pm

@vubidugil
link updated in original post
B
94
S
33
G
114
Posts: 5,359
Reputation: 73,779


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 10 guests