Autotiling

I know it is asked before but in those questions, the answer was to use an external editor. However, I require runtime manipulation with autotiling so external editors would not be sufficient. Some implementations I saw require to order tiles in a specific order for it to work and it is very hard to implement (in my opinion). I want to ask whether it would be possible for me to import bitmasking done in an external map editor (tiled) to Defold Engine. Or is there another method I can use.

I personally reused code from the LDtk editor and used its autotiling mechanic for runtime manipulation. But you’d have to covert its code to Lua from Haxe. Haxe supports automatic Lua transpilation but I wouldn’t trust it.

I am not familiar with how LDTK handles autotiling, can you elaborate on how you were able to get the autotiling code? How LDTK handles autotiling?

In LDtk you can setup rules for autotiling, e.g. if left cell is ground and right cell is ground and top cell is empty pick a ground tile with grass on the top. It’s more flexible than bitmasks but can have a big number of rules.
I copied the code from LDtk sources, adapted for my needs and ran it in a Haxe project but it’s possible to transpile/rewrite it to Lua.

Can you share the code in Haxe. And I would like to ask, how would I be able to define rules, will I need to configure the code for that each time or will be able to send it separately as an argument.

Here is the function that starts autotiling for entire map. https://github.com/deepnight/ldtk/blob/e3073565cd92a7d3c5da10e902fb57a25d8789fe/src/electron.renderer/data/inst/LayerInstance.hx#L1116

The rules are defined in the editor and stored in the LDtk project file (json format). You can parse it yourself in Lua and extract the rules.

This code looks very intertwined with the overall project, I cannot even understand it. Is there an alternative way to use LDTK to import these rules?

May be can helpful

1 Like

This is a very awesome project, thanks for sharing how its done but a main concern that I have is to prepare the source image since it takes a lot of time. That’s why I would like to utilize an external editors functionality.