Phaser API Documentation

setCollision(indexes, [collides], [recalculateFaces], [layer], [updateLayer])


Sets collision on the given tile or tiles within a layer by index. You can pass in either a single numeric index or an array of indexes: [2, 3, 15, 20]. The collides parameter controls if collision will be enabled (true) or disabled (false).

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


name type arguments Default description
indexes number | array

Either a single tile index, or an array of tile indexes.

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.

updateLayer boolean <optional> true

If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost.


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

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