# Run function on tile overlap based on parameter

**URL:** <https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328>\
**Category:** Phaser 3\
**Created:** [December 14, 2018, 7:57pm UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328 "2018-12-14T19:57:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jursdotme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jursdotme/32/212_2.png) [@Jursdotme](https://phaser.discourse.group/u/Jursdotme)\
**Post date:** [December 14, 2018, 7:57pm UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328/1 "2018-12-14T19:57:26Z")

</div>

I have a tilemap where som tiles are “lava”. I want to run my “kill player” function on overlap with these tiles.

In the map i plan to have lava, spikes and other tiles that kill the player so i have given all these tiles a parameter (in the Tiles editor). Now i want to check overlap with player and the tiles with the “kill” parameter and run my function.

Im thinking the setTileIndexCallback method is the way to go but it wants a tile ID. There may me a way to get the ID of all tiles with the specified parameter?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 14, 2018, 9:27pm UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328/2 "2018-12-14T21:27:19Z")

</div>

You can do something like

```javascript
tilemapLayer.getTilesWithin() // all tiles
  .filter(function (tile) { 
    return tile.properties.isLava;
  });

```

---

<div class="post-metadata">

**Author:** ![Jursdotme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jursdotme/32/212_2.png) [@Jursdotme](https://phaser.discourse.group/u/Jursdotme)\
**Post date:** [December 15, 2018, 8:53am UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328/3 "2018-12-15T08:53:45Z")

</div>

Thanks samme!

I need to get better at looking in the prototypes. This looks like it’ll get me over the biggest hurdle.

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [December 16, 2018, 9:48pm UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328/4 "2018-12-16T21:48:29Z")

</div>

```javascript
tilemapLayer.filterTiles(function (tile) { 
  return tile.properties.isLava;
}); // → Array.<Tile>

```

---

<div class="post-metadata">

**Author:** ![Jursdotme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jursdotme/32/212_2.png) [@Jursdotme](https://phaser.discourse.group/u/Jursdotme)\
**Post date:** [December 17, 2018, 6:44pm UTC](https://phaser.discourse.group/t/run-function-on-tile-overlap-based-on-parameter/328/5 "2018-12-17T18:44:56Z")

</div>

Thanks. Thats a little cleaner.

I ended up with the following:

```
const deadlyTiles = this.foreground.filterTiles(tile => tile.properties.deadly).map(x => x.index);
const deadlyTilesId = [...(new Set(deadlyTiles))];

this.foreground.setTileIndexCallback(deadlyTilesId, this.killPlayer, this);
this.physics.add.overlap(this.player, this.foreground);
```
