# While using createStaticLayer I get an error regarding an undefined tileWidth

**URL:** <https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827>\
**Category:** Phaser 3\
**Created:** [June 7, 2022, 1:55pm UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827 "2022-06-07T13:55:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschilli](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@mschilli](https://phaser.discourse.group/u/mschilli)\
**Post date:** [June 7, 2022, 1:55pm UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827/1 "2022-06-07T13:55:44Z")

</div>

I am using phaser version 3.11.0.

When I am calling the line `map.createStaticLayer('stone')` I am getting the following error.

 ![logoutput](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/d/d808fdd7c37a700dbee594887a6a726f89112c96.png)

However right before I am calling `console.log(map)` the `tileWidth` appears to be defined as 32. Without the `createStaticLayer()` call the code runs with no errors and displays the background color defined in the config variable in `index.html`. Also if I purposely misspell the word `stone` I only get a warning that `Cannot create tilemap layer, invalid layer ID given: stonze`.

I have been trying to figure out how to fix it but I’m really stuck on this issue.

**scene-one.js**

```javascript
class SceneOne extends Phaser.Scene {

    constructor () {
        super('SceneOne');
    }

    init() {
     
    }

    preload() {
        this.load.tilemapTiledJSON('map', 'assets/map/example_map.json');
        this.load.image('tileset' , 'assets/map/tilesheet.png')
    }

    create(data) {
        let map = this.add.tilemap('map');
        map.addTilesetImage('tilesheet', 'tileset'); // tilesheet is the key of the tileset in map's JSON file

        console.log("hi")
        console.log(map)
        map.createStaticLayer('stone')
        console.log(map)

    }

    update(time, delta) {
  
    }
}

var sceneOne = new SceneOne

```

**index.html**

```javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="//cdn.jsdelivr.net/npm/phaser@3.11.0/dist/phaser.js"></script>
    <script src="js/scene-one.js" type="text/javascript"></script>
    <title>game</title>
</head>
<body>
    <div id='game'></div>    
    <script>
        const phaserConfig = {
            type: Phaser.AUTO,
            parent: "game",
            width: 1280,
            height: 720,
            backgroundColor: "#5DACD8",
            scene: [SceneOne]
        };

        const game = new Phaser.Game(phaserConfig);
    </script>     
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 7, 2022, 2:13pm UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827/2 "2022-06-07T14:13:25Z")

</div>

👋

```javascript
map.createStaticLayer('stone', map.tilesets[0]);

```

or you can pass the result of `addTilesetImage()`.

---

<div class="post-metadata">

**Author:** ![mschilli](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@mschilli](https://phaser.discourse.group/u/mschilli)\
**Post date:** [June 7, 2022, 11:26pm UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827/3 "2022-06-07T23:26:45Z")

</div>

@samme thanks your suggestion of including `map.tileset[0]` as a parameter worked. Can you explain what I was missing, because I have seen plenty of examples that didn’t include this.

I also tried googling the function and am looking at the following URLs but I am unable to quickly find the description for this function.

[https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.StaticTilemapLayer.html](https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.StaticTilemapLayer.html)  
[https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html](https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html)

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [June 8, 2022, 1:26am UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827/4 "2022-06-08T01:26:33Z")

</div>

The `tileset` argument is required. Since Phaser v3.50 there are no static vs. dynamic tilemap layers, so the method is [createLayer()](https://newdocs.phaser.io/docs/3.55.2/focus/Phaser.Tilemaps.Tilemap-createLayer).

---

<div class="post-metadata">

**Author:** ![mschilli](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@mschilli](https://phaser.discourse.group/u/mschilli)\
**Post date:** [June 8, 2022, 2:28am UTC](https://phaser.discourse.group/t/while-using-createstaticlayer-i-get-an-error-regarding-an-undefined-tilewidth/11827/5 "2022-06-08T02:28:05Z")

</div>

Thank you so much for the help!
