Physics.Ninja#convertTilemap()

convertTilemap(map, layer, slopeMap) → {array}

Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics tiles.
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.

In Ninja the Tiles have an ID from 0 to 33, where 0 is 'empty', 1 is a full tile, 2 is a 45-degree slope, etc. You can find the ID
list either at the very bottom of Tile.js, or in a handy visual reference in the resources/Ninja Physics Debug Tiles folder in the repository.
The slopeMap parameter is an array that controls how the indexes of the tiles in your tilemap data will map to the Ninja Tile IDs.
For example if you had 6 tiles in your tileset: Imagine the first 4 should be converted into fully solid Tiles and the other 2 are 45-degree slopes.
Your slopeMap array would look like this: [ 1, 1, 1, 1, 2, 3 ].
Where each element of the array is a tile in your tilemap and the resulting Ninja Tile it should create.

Parameters
Name Type Description
map Phaser.Tilemap

The Tilemap to get the map data from.

layer number | string | Phaser.TilemapLayer

The layer to operate on. If not given will default to map.currentLayer.

slopeMap object

The tilemap index to Tile ID map.

Returns
array -

An array of the Phaser.Physics.Ninja.Tile objects that were created.

Source code: physics/ninja/World.js (Line 246)
doc_phaser
2017-02-14 10:59:54
Comments
Leave a Comment

Please login to continue.