setCollisionByProperty not working (the way I think it does)

I’ve created a test map with Tiled and I’m trying to get my character to collide with a layer on it using setCollisionByProperty but it’s never colliding (here’s the game running).

I think I’m doing something dumb/obvious but I’ve been toying with it for quite some time and can’t figure out what it is. My only guess is that there needs to be a certain order to when I set collision properties or make layers/sprites but I haven’t found an order that works yet.

I also noticed that the debug shading for the collision layer doesn’t show up at all so it seems like the layer isn’t being shown as collidable at all. I can’t tell why that’s the case though.

Any thoughts?

I think the tiles are missing the collides property (or any property). In Tiled, make sure you’re editing custom properties of a Tile, not Tile Layer.

This will also work:

this.collidesLayer.setCollision([1842, 1843, 1843, 1843, 1843, 1843, 1843, 1843, 1843, 1844, 2085, 2086, 2087, 2088, 2186, 2187, 2187, 2187, 2187, 2187, 2187, 2187, 2187, 2188, 2189, 2190, 2190, 2190, 2190, 2190, 2190, 2193, 2194, 2196]);
1 Like

I think this is the key here. I have no idea how to edit properties of just the tile, not the whole layer. I guess I’ll go ahead and dig through Tiled documentation for it.

How did you get the following indices? I’m guessing you did it using something generated (from Tiled) but I’m not certain.

this.collidesLayer.setCollision([1842, 1843, 1843, 1843, 1843, 1843, 1843, 1843, 1843, 1844, 2085, 2086, 2087, 2088, 2186, 2187, 2187, 2187, 2187, 2187, 2187, 2187, 2187, 2188, 2189, 2190, 2190, 2190, 2190, 2190, 2190, 2193, 2194, 2196]);

In Tiled, you can click on a tileset tile (not a map tile) and then edit properties.

I found the tile indices in the JSON data, but see Show tile indexes (v3).

1 Like

Wow, didn’t realize I’d have to do this in the tileset itself, amazing! Once I clicked on the good old wrench paper, the tileset editor showed up and I could select different tiles and apply properties to each of those tileset tiles. I never would have found that without your help. Thank you! :pray:

42%20PM