How to create a map array with multiple layers?

I’m trying to create a map array without using JSON because I want to dynamically generate the map:

const map = [
      [
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1],
        [-1, -1, -1, -1, -1, -1, -1, -1]
      ],
      [
        [3, 3, 3, 3, 0, 3, 3, 3],
        [3, 3, 3, 3, 7, 3, 3, 3],
        [4, 5, 5, -1, -1, -1, 5, 6],
        [11, -1, -1, -1, -1, -1, -1, 13],
        [11, -1, -1, -1, -1, -1, -1, 13],
        [11, -1, -1, -1, -1, -1, -1, 13],
        [11, -1, -1, -1, -1, -1, -1, 13],
        [18, 19, 19, 19, 19, 19, 19, 20]
      ],
      [
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15],
        [15, 15, 15, 15, 15, 15, 15, 15]
      ]
      
    ]
    const map = this.make.tilemap({data: map, tileWidth: 32, tileHeight: 32});
    const tileset = map.addTilesetImage("spritesheet", "tiles");
    const layer = map.createStaticLayer(0, tileset, 0, 0);
    const layer1 = map.createStaticLayer(1, tileset, 0, 0);
    const layer2 = map.createStaticLayer(2, tileset, 0, 0);

But it does not work, I did not take a look at the documentation:

https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html

createStaticLayer(layerID, tileset [, x] [, y])

and “createStaticLayer” is asking for the layerID as I am passing, is it wrong the way I was creating the array for a 3-layer map?

Hi,

In ganeral I don’t answer yet questions on the official forum about Phaser 3 because I still maintain Phaser 2 (CE), so after reading your comment on stackexchange I really don’t know what to say as I guess playing a bit with the code can make it work and that Game Development on stackexchange is more for research purpose, so except this you can open an issue on the official GitHub repo if you can’t still fix it or join the slack/discord and start discuss about this bug (maybe it is one I don’t know)

Hello @perdugames

The tilemap function takes as data a multi-dimensional array of type number[][]. You are trying to load a more complex array, which will not work, as far as I know.

Here is an example with only one map array, which works:
https://labs.phaser.io/edit.html?src=src\game%20objects\tilemap\static\create-from-array.js