About Monkey 2 › Forums › Monkey 2 Programming Help › Tiled
This topic contains 20 replies, has 5 voices, and was last updated by 
 juliocmfj 1 year, 5 months ago.
- 
		AuthorPosts
 - 
		
			
				
August 25, 2017 at 11:05 pm #9996
Is there any module to load maps made using the Tiled editor?
If not, I will start developing a module for this purpose using Json to read the data.
August 26, 2017 at 12:56 am #9997That would be great!
August 26, 2017 at 2:19 am #9998Hey, Mark! I had made a class that did this in BlitzMax, except that the reading was done .csv exported by Tiled.
Today Tiled has greatly changed the way information is stored. The tiles information is separated from the main map. I am not Json’s master, but I will learn to develop this class that I believe will greatly help everyone.
Start tomorrow and God willing I will get something functional soon and post here in the forum.
August 26, 2017 at 4:09 am #10000Not sure if its any Help, but Samah did create a Tiled Reader for MonkeyX1 for Diddy:
https://github.com/swoolcock/diddy/blob/develop/src/diddy/tile/diddyreader.monkey
BTW Playniax has created a Pyro 2 Tiled converter:
https://playniax.itch.io/pyro-2-tiled-converter
August 26, 2017 at 5:01 am #10001Therevills, I really liked the Playniax version, which is paid and I do not have an internacional credit card.
And about the Diddy version, it’s 2015, Tiled has changed a lot from that period to today…
But I will give a study and see a way to develop this module based on the current version of Tiled.
If you have more suggestions, send it helps a lot.
August 26, 2017 at 8:52 am #10005I was able to read and interpret pratically all information from the main file that Tiled generates in *.json. However, I’m having trouble reading and manipulating JsonArray.
Any simple example?
August 26, 2017 at 9:03 am #10006Monkey1234567891011121314151617181920212223242526#Import "<std>"Using std..Const json:="{~qmyarray~q:[ 1,2,3,4,5 ]}"Function Main()Local jobj:JsonObject=JsonObject.Parse( json )Local jarr:JsonArray=jobj.GetArray( "myarray" )Print "Length="+jarr.LengthFor Local i:=0 Until jarr.LengthPrint "Element["+i+"]="+jarr.GetNumber( i )NextEndBoth JsonObject and JsonArray have GetString,GetNumber,GetObject and GetArray methods, JsonObject.GetBlah() is ‘keyed’ by string, JsonArray.GetBlah() is keyed by int index.
August 26, 2017 at 9:45 am #10007Hey guys, after reading this I just decided to make it FREE!
You can download it for free or name your own price… Thanks.
https://playniax.itch.io/pyro-2-tiled-converter
Now there is always room for alternatives so don’t let it stop you from creating your own!
August 26, 2017 at 9:55 am #10008I understand how it works with a simple array. But when it has:
“array” : [
{
“data” : [0, 1, 2…],
“data2” : “test”
}
]In this case, an array with several different elements and other arrays inside it…
I can not read this type of array.
August 26, 2017 at 10:00 am #10010Hey Playniax, only now that I’ve seen your comment.
Well, great initiative of yours. I do not even know how to thank. I know it takes a lot of work to develop these things, but you can be sure that your attitude will be of great help to those who can not afford it.
Thank you so much, really!
August 26, 2017 at 10:38 am #10011Monkey12345678910111213141516171819202122232425262728293031323334#Import "<std>"Using std..Const json:="{~qmyarray~q:[1,~qblah~q,{~qname~q:~qmarky~q}]}"Function Main()local jarr:=JsonObject.Parse( json ).GetArray( "myarray" )For Local i:=0 Until jarr.LengthIf jarr.GetValue( i ).IsNumberPrint jarr.GetNumber( i )Else If jarr.GetValue( i ).IsStringPrint jarr.GetString( i )else If jarr.GetValue( i ).IsObjectLocal jobj:=jarr.GetObject( i )EndifNextEndThere are several ways to do this, but the basic idea is to test the JsonValue type of each element.
But I would have though the format for a tile map would use ‘known’ keys etc. Otherwise, kind of a PITA.
August 26, 2017 at 4:51 pm #10012Took a look at a simple json output from Tiled.
The “layers” array is actually an array of objects. Each object contains info about each map layer. The “data” array within the layer object contains the actual map data.
I wrote a little sample here that reads the data, stores it in an array, and prints the info. Not complete, but hopefully will help.
Hmm, When I post the code here, I get a “Forbidden” error. well, you can grab the source here. https://drive.google.com/open?id=0B1zQ5dfVU3jbZGtjZmtCckx3SWM
August 27, 2017 at 1:45 am #10017The json thing is, I’ve never worked with him. The first time I made the class that handled tile maps made by Tiled, I used the *.csv format and read using String[] and methods like Split(“”) to make inclusion in the arrays…
Now having to work with json is a whole new thing for me. With Mark’s secons example, I was able to understand the JsonObject question. I just did some tests and I was able to read those data.
TomToad, I’ll tale a look at your code to learn more about json. Thank you for all your help and thanks again to Playniax for “releasing” the class he developed for the same purpose.
August 27, 2017 at 2:15 am #10018Monkey1Success!!!!August 28, 2017 at 7:08 am #10052First test completed successfully!!!!
I was able to load and display a map with a layer and a tileset associated with it.
In the image is the print with the map being executed and the main code.
Attachments:
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.
		
		
	