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 / Using LDtk (tile editor) with AGK tier 1

Years of Service
User Offline
Joined: 27th Mar 2021
Posted: 21st Dec 2022 00:09 Edited at: 21st Dec 2022 00:18
This post will tell you how I used LDtk to make a level for Project Jupiter

If like me you want to add Enums, Entities as well as tile sets with a simple layering system LDtk lets you do that in a productive way. And adding all this into your AppGameKit project is easy too, with the LDtkFileType.load(loadFileStr) command. But before programming you will need to make your level in LDtk.

When you are happy with your creation, set the 'Save Levels To Separate Files' box and ensure you are saving the .ldtk extension.

For project Jupiter I made a really simple file with three layers, a wall layer, a fill layer, and an entity layer. The wall layer is where the ship cannot go and has physics applied, the fill layer is just a sprite with no physics and the entity is where I want the enemies to be.

The next part of the import into AppGameKit requires the use of TYPES. If you don't know about setting up types you can read up all about them here: All we need to do here is set up a TYPE and then latter we read our .json file into it so the data is stored in memory ready to be used. The code below shows the TYPE I made for Project Jupiter.

and for those who like to read .json files, here it is from the .LDtk save.

Now, here's the bit that got me stuck for a bit and I had to do a bit of head scratching to figure out what was going on. If you take a look at the .json file, it starts with a { and ends with a }. But AGK's .json command e.g. loadmyData.load(thisfile$) wants the file to be bracketed in a [ and a ]. This is because loading .json files into AppGameKit is an iterative function and the command expects it to be denoted as such. The solution is then to add [ at the file start and a ] at the file end. And this can be done easily in code:

Next load in your tile sets. How you do this is up to you. I loaded them into an array using subimage.txt file as described here :

With everything now ready, to add our level into our game we need to parse the data we loaded from .json file add in the tiles and put them into the world in the correct places. The code I used to do this is shown below.

LDtk has much to offer in terms of 2D level design and it is worth a look. Because the data can be saved as a .json then to read and parse the data is easy, just remember to add your '[]' on the file or AppGameKit can't load it. Also, LDtk records all the information into the .json so this is accessible from the .json structure, if you know where to look. Everything you need is well documented :

If you want to play Project Jupiter it is here for download :


Login to view attachments
DBPro Master
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Dec 2022 20:08
I've never heard of ldtk before, how would you say it stacks up against Tiled?
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Years of Service
User Offline
Joined: 27th Mar 2021
Posted: 2nd Jan 2023 16:04 Edited at: 2nd Jan 2023 16:12
LDtk is highly capable in terms of workflow. Choosing between Tiled and LDtk I prefer the latter. There are still some features available in Tiled which aren't in LDtk like the History Editor and the Tile Collision Editor. However, LDtk is a work in progress and 1.2.0 has just been released (today) which adds the following :
1. Auto Layer Rules Assistant.
2. Reworked Entity Field Visuals
3. Auto Layer Rules Remapping.
4. Icons for Entities (I like this one!)
5. In Editor Enum Tag Display.
6. Custom Script Commands.

You can find out more here :

Image screenshot of editor used to create multiple levels for Red Tonya


Login to view attachments
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 6th Feb 2023 22:47 Edited at: 6th Feb 2023 22:54
Hey i try to use this editor for one of my projects.
So i started to rewrite your code to use references instead of globals for example:

And then

And the flip sprite function looks like this:

And i think we could easily read the relative path of the sprite sheet and generate the subimage file from the information given.
Write a neat function that gives us a Subimage List and maybe even create a function that can do it all in one go.

I also have a question:
Why did you use this ?

Isn't a list of LDtk_ldTKrootT enough ?

And what are your thoughts on using LDtk and the Virtualresolution in AppGameKit?
I normally use a virtual resolution of 100x100 and GetScreenBoundsLeft ect. to position stuff so i have to post process the positions of the tiles as we can't scale the tiles in the editor right ?

I didnt really dive into LDtk much but it looks very promising and wanted to give it a try, so thanks for sharing and pointing us to it.

Login to post a reply

Server time is: 2024-02-24 04:15:16
Your offset time is: 2024-02-24 04:15:16