Loading your new and shiny world can be done in 4 different ways.
1. The “super easy” way
No parsing required. You can ignore the LDtk JSON file completely:
- Enable the
Export layers as PNGin the project settings,
- Simply load your level layer in your game using plain and simple PNG images.
- If you need IntGrid values, you can check among the exported PNGs and look for a tiny image: it’s a direct export of the IntGrid layer, where 1 pixel is 1 layer grid cell.
- If you need extra data, like Entities, you might need some very simple JSON parsing. Don’ worry, there’s nothing crazy here, see below.
2. The QuickType way
QuickType can generate a full JSON parser for many languages including Ruby, Dart, Objective-C etc. It’s based on the official JSON schema, so it’s always guaranteed to work even with latest version.
- Grab the Json Schema file: LDtk latest Json Schema,
- Paste it in Quicktype online app,
- Select the JSON Schema as Source type,
- Pick your favorite language and adjust options as you wish,
- Download the resulting source code & enjoy
3. The home-made way
You may check the API section for existing importers and tools.
If nothing fits your needs, it’s quite easy to parse the JSON by yourself. Don’t worry, we’ve got your back.
- First thing to know: you can ignore all JSON sections marked as “Internal editor data“ in the JSON documentation. As this label suggests, game devs don’t really need these elements. That’s a big part of the JSON.
- If you only need level data, check the
levelsarray in the JSON root.
- Rely heavily on fields named with a double underscore (eg.
__x), as these values exist for the sole purpose of making your dev life easier.
- Get started by reading the JSON overview section.
4. The Tiled TMX way
Tiled is a very popular and complete tool to create levels. Many game frameworks support it pretty well. LDtk can export to Tiled TMX file format: see documentation. This could be a good approach to try and integrate LDtk quickly.
Warning: the Tiled export comes with some limitations.