Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / JSON Demo Project - Loads a Pyxel map and displays it

Author
Message
RickV
TGC Development Director
24
Years of Service
User Offline
Joined: 27th Apr 2000
Location: United Kingdom
Posted: 27th Sep 2017 08:39
Hi Everyone,

I'm sharing a demo that shows better how to use the new JSON featues in AppGameKit. It's been kindly made and shared by forum member hughbus

You can DOWNLOAD IT HERE.

The Pyxel map editor that hughbus used can be found HERE

We will ensure the help is updated with more JSON information soon.

Thanks go to hughbus for creating this so quickly and offering it to the community.

Rick
Development Director
TGC Team
Hughbus
AGK Backer
11
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 27th Sep 2017 09:22
Hello All,

Hopefully this project can help everyone get started with the new JSON loading additions. Once you know how it works it's actually pretty quick!

In my demo project it will load in a basic city map. You can replace the loadMap( "CityMap.json" ) and createTileset( "CityMap.png", Map01.tilewidth, 0 ) with DungeonMap.json and DungeonTiles.png respectively for another example map that is of different dimensions, and tilesize (16 pixels instead of 32)

To roughly explain how I am importing the JSON files generated by Pyxel Edit:
~Referencing the PyxelLoader.agc file

JSON consists of data objects and arrays which can then contain their own arrays or data objects. Using AppGameKit types you can replicate the data structure of the JSON file to be imported.

I create types that represent the farthest branches of the JSON file and work backwards. So starting at the tile level, then layers and finally the map info. All in all it took 3 types to represent the Pyxel Edit JSON File. Any arrays are create without size (empty square brackets myArray[]) because the new commands take care of exapnding them appropriately

Once you have laid out the data structure correctly using types the next step is quite quick. I OpenToRead the JSON file, create a memblock from the file and then convert that memblock to a string (learned from Paul that this is substantially quicker than reading in the file line by line). You then declare your type (that matches the JSON data structure) and import your string data (once JSON file) using myType.fromJson(String$).

You can then just use your new type to access any data you need.

e.g. currentMap.layers[0].tiles[0].ID

In my project I have taken it a step further by abstracting the process into functions that return the JSON Data as a type. This just means that everytime i want to import a JSON I do the following:

myMap as tileMapType
myMap = LoadMap(filename$)

So I can have lots of level maps loaded at once, etc etc.

As I said, hopefully this will help people get started. Having these new commands gives us to so many cool tools out there that support JSON format not to mention handling your own data in nice ways. Pyxel Edit was just one tool that came to mind for me.

Any questions just send them through!
maddin
5
Years of Service
User Offline
Joined: 1st Jun 2019
Location:
Posted: 18th Jun 2019 16:09
Hi Hughbus,

unfortunately the download link to your tool is dead.
Can you provide a new one for me?

Thank you

Martin
Hughbus
AGK Backer
11
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 30th Aug 2019 14:53
Hey @maddin, sorry I haven't responded a heck of a lot sooner. I dug up the old project. Hope it can still help you and anyone else whose interested. Let me know how you go and if you find any issues

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-22 17:13:16
Your offset time is: 2024-11-22 17:13:16