Specific tile collision with specific sprite

Is it possible to have specific tile collide only with player and ignores every other sprite? (all sprites collide with the same layer in which that tile is)

I use setTileIndexCallback

// tile id in json +1
this.mapLayer.setTileIndexCallback(11, this.city1, this);

this is map.json for city tile, id is 10


I don’t work with tiles much, so I’d normally handle this when setting up the collider. When you add a physics collider, there’s an optional 4th parameter for a processCallback function. This function provides two arguments (the two objects that are colliding) and must return a boolean. If it returns false, the regular callback function (the 3rd parameter) won’t get called at all, and the collision will be ignored. But I’m not sure what arguments are provided for a collision with a tile - does it give you the sprite and the specific tile, or just the sprite and the whole layer?

While poking around the examples, I noticed that setTileIndexCallback has similar functionality but is kind of not mentioned at all in the docs, as far as I can tell. The callback function in mapLayer.setTileIndexCallback provides two arguments, (sprite, tile), so you can check if the sprite is your player or another sprite. In this case it seems that if this function returns TRUE, the collision will be ignored, and your other sprites will be able to pass right through the tile. Check out the function ‘hitCoin’ in this Phaser 3 example.

Post back and let us know what worked for you, I’m kind of curious!

Thank you, this works I saw this yesterday but I didn’t really know what this.city1 is but now I know.

Thank you, both of these can be used. Both of them pass tile and sprite as parameters, but I think that the first solution is probably better if you want to check something for a specific sprite, and the second if you have multiple sprites you want to check when they collide with tile. stanleyseow post answered my question but I didn’t know what this.city1 is.