Phaser API Documentation

setCollisionByProperty(properties, [collides], [recalculateFaces], [layer])


Sets collision on the tiles within a layer by checking tile properties. If a tile has a property that matches the given properties object, its collision flag will be set. The collides parameter controls if collision will be enabled (true) or disabled (false). Passing in { collides: true } would update the collision flag on any tiles with a "collides" property that has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can also use an array of values, e.g. { types: ["stone", "lava", "sand" ] }. If a tile has a "types" property that matches any of those values, its collision flag will be updated.

If no layer is specified, the maps current layer is used.


name type arguments description
properties object

An object with tile properties and corresponding values that should be checked.

collides boolean <optional>

If true it will enable collision. If false it will clear collision.

recalculateFaces boolean <optional>

Whether or not to recalculate the tile faces after the update.

layer string | number | Phaser.Tilemaps.TilemapLayer <optional>

The tile layer to use. If not given the current layer is used.


Return this Tilemap object, or null if the layer given was invalid.

Since: 3.0.0
Source: src/tilemaps/Tilemap.js (Line 2084)