Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 4 characters in body
Source Link
PerduGames
  • 289
  • 2
  • 14

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

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

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

Source Link
PerduGames
  • 289
  • 2
  • 14

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 layers?