# How to create a map array with multiple layers?

**URL:** <https://phaser.discourse.group/t/how-to-create-a-map-array-with-multiple-layers/3124>\
**Category:** Phaser 3\
**Created:** [July 15, 2019, 6:51pm UTC](https://phaser.discourse.group/t/how-to-create-a-map-array-with-multiple-layers/3124 "2019-07-15T18:51:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perdugames](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/perdugames/32/1722_2.png) [@perdugames](https://phaser.discourse.group/u/perdugames)\
**Post date:** [July 15, 2019, 6:51pm UTC](https://phaser.discourse.group/t/how-to-create-a-map-array-with-multiple-layers/3124/1 "2019-07-15T18:51:15Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![nazimboudeffa](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nazimboudeffa/32/282_2.png) [@nazimboudeffa](https://phaser.discourse.group/u/nazimboudeffa)\
**Post date:** [July 29, 2019, 4:49pm UTC](https://phaser.discourse.group/t/how-to-create-a-map-array-with-multiple-layers/3124/2 "2019-07-29T16:49:29Z")

</div>

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](https://gamedev.stackexchange.com/a/174090/128558) 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](https://github.com/photonstorm/phaser/issues) 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)

---

<div class="post-metadata">

**Author:** ![digitsensitive](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/digitsensitive/32/349_2.png) [@digitsensitive](https://phaser.discourse.group/u/digitsensitive)\
**Post date:** [July 30, 2019, 10:19am UTC](https://phaser.discourse.group/t/how-to-create-a-map-array-with-multiple-layers/3124/3 "2019-07-30T10:19:23Z")

</div>

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](https://labs.phaser.io/edit.html?src=src%5Cgame%20objects%5Ctilemap%5Cstatic%5Ccreate-from-array.js)
