convertTilemap(map, layer, addToWorld, optimize) → {array}
Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics bodies.
Only call this after you have specified all of the tiles you wish to collide with calls like Tilemap.setCollisionBetween, etc.
Every time you call this method it will destroy any previously created bodies and remove them from the world.
Therefore understand it's a very expensive operation and not to be done in a core game update loop.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
map | Phaser.Tilemap | The Tilemap to get the map data from. | ||
layer | number | string | Phaser.TilemapLayer | <optional> | The layer to operate on. If not given will default to map.currentLayer. | |
addToWorld | boolean | <optional> | true | If true it will automatically add each body to the world, otherwise it's up to you to do so. |
optimize | boolean | <optional> | true | If true adjacent colliding tiles will be combined into a single body to save processing. However it means you cannot perform specific Tile to Body collision responses. |
Returns
An array of the Phaser.Physics.P2.Body objects that were created.
- Source code: physics/p2/World.js (Line 1688)
Please login to continue.