1. Home
  2. Game dev
  3. Loading LDtk in your game

Loading LDtk in your game

Loading your new and shiny world can be done in 4 different ways.

1. The “super easy” way

Exporting layers as individual PNGs

No parsing required. You can ignore the LDtk JSON file completely:

  1. Enable the Export layers as PNG in the project settings,
  2. Simply load your level layer in your game using plain and simple PNG images.
  3. 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.
  4. 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.

  1. Grab the Json Schema file: LDtk latest Json Schema,
  2. Paste it in Quicktype online app,
  3. Select the JSON Schema as Source type,
  4. Pick your favorite language and adjust options as you wish,
  5. 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 levels array in the JSON root.
  • Rely heavily on fields named with a double underscore (eg. __tile, or __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.