How do I add collisions to imported Tiled tilemaps?

When importing maps from Tiled, how can I get collisions to work with the collision shapes I’ve defined in the Tiled Map Editor?
I’ve had a hard time finding clear information about this. The only thing I’ve come across is an auto-generated collision feature, but it seems too complex for a simple pixel game.

Would I need to import my maps in Lua instead and write a custom importer that reads the collision data from the Tiled file?

Maybe there are Lua libraries that could help with collisions? I found this: GitHub - erinmaus/slick: slick is a simple to use polygon collision library inspired by bump.lua

1 Like

bump

I just point back to the tilesheet .png file and let defold handle the collisions.

Or are you asking how to setup collisions in tiled and then use them in defold?

If so, I’m not a pro at that process, but here’s what I got from CHAT GPT:

https://chatgpt.com/s/t_68f34b986e50819199db1c3169b8c609

And Claude said the same thing.

You have a couple of options for handling collisions with Tiled and Defold:

1. Define collision shapes in Tiled (recommended approach)

  • Create an Object Layer in Tiled

  • Add collision shapes (rectangles, polygons, etc.) on this layer

  • When you export and import the Tiled map into Defold, you can parse these object layers

  • Then programmatically create Defold collision objects based on the Tiled object data

2. Set up collisions entirely in Defold

  • Import your Tiled map as a tile map

  • Manually create collision objects in Defold that match your level geometry

  • This gives you more direct control but is more tedious for complex maps

The typical workflow:

  • Defold doesn’t automatically convert Tiled collision layers into Defold collision objects

  • You’ll need to write some code to read the Tiled object layer data and spawn collision objects in Defold

  • Many developers use Tiled for visual layout and rough collision placement, then use a script to generate the actual Defold collision objects at runtime or in the editor

What works well:

  • Use Tiled’s object layers to mark where collisions should be

  • Export to Lua or JSON format

  • Parse this data in Defold to create collision objects programmatically