// When player overlap , call collectItem1, collectItem2
this.physics.add.overlap(player, item1Layer,collectItem1, null, this );
this.physics.add.overlap(player, item2Layer,collectItem2, null, this );
I’m not sure, but it seems you are doing this over the whole layer, like every tile of it… shouldn’t you check for overlap only on some tiles, where your items are ?
Which checks only the places where the 12th tileset tile is used.
Then collectItem1() should work well, and only when you hit some of those 12th tiles…
Well, you may count manually the tiles on your tileset…
or you may read/explore your tilemap.json file to find this index - it’s easier if you create a layer with only the tile you want on it (then you’ll find this index in an ocean of 0)
I guess there are better ways but that’s the ones I know
And yeah, I agree with you that setTileIndexCallback is quite confusing…
I found it in the Phaser exemples, it’s a strange logic but it works fine.
I’m not sure that setTileIndexCallback affects tile overlaps. I think overlap() with a tile layer always gives every overlapping tile (and empty ones).
You may need
function collectItem1 (sprite, tile) {
if (tile.index !== 12) return;
console.log('Item1', tile.x, tile.y)
item1Layer.removeTileAt(tile.x, tile.y);
}
Well, I tested setTileIndexCallback() and it triggered overlap() callback only on the one tile I pointed.
But beside of this one kind of tile my layer was empty…