# Unable to pass array of tilesets to .createDynamicLayer not .createStaticLayer

**URL:** <https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505>\
**Category:** Phaser 3\
**Created:** [March 14, 2020, 7:21pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505 "2020-03-14T19:21:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![malinda-lin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/malinda-lin/32/2975_2.png) [@malinda-lin](https://phaser.discourse.group/u/malinda-lin)\
**Post date:** [March 14, 2020, 7:21pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/1 "2020-03-14T19:21:52Z")

</div>

My tiles load properly, layerOne will render the corresponding tile images but layerTwo does not. Notice that in layerTwo I passed in an array with all the tilesets, I got different error messages depending on how I pass in an array of tilesets ~~(heroMap.tilesets doesn’t display console errors but won’t render the tile images either)~~  
My interpretation of the documentation is that an array of tilesets is allowed, am I reading that wrong? Is there any way I can pass in multiple tilesets for different layers or is this bad practice anyway?  
[https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html](https://photonstorm.github.io/phaser3-docs/Phaser.Tilemaps.Tilemap.html)

My git repo: [https://github.com/malinda-lin/Hero](https://github.com/malinda-lin/Hero)

```
  heroMap = this.add.tilemap('heroMap');
  overWorldTiles = heroMap.addTilesetImage('Overworld', 'overWorld');
  hyptosisTiles = heroMap.addTilesetImage('terrainother', 'hyptosis');
  grassTiles = heroMap.addTilesetImage('grass', 'grass');
  treeTiles = heroMap.addTilesetImage('terrain', 'tree');
  allTiles = [overWorldTiles, hyptosisTiles, grassTiles, treeTiles];
  layerOne = heroMap
    .createStaticLayer('groundLevel', overWorldTiles)
    .setDepth(-2);
  layerTwo = heroMap
    .createStaticLayer('upperLevel', allTiles)
    .setDepth(-1);
```

---

<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:** [March 14, 2020, 7:29pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/2 "2020-03-14T19:29:26Z")

</div>

That looks right, but what were the errors?

---

<div class="post-metadata">

**Author:** ![malinda-lin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/malinda-lin/32/2975_2.png) [@malinda-lin](https://phaser.discourse.group/u/malinda-lin)\
**Post date:** [March 14, 2020, 7:46pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/3 "2020-03-14T19:46:25Z")

</div>

git repo: [https://github.com/malinda-lin/Hero](https://github.com/malinda-lin/Hero)

error when passing in “allTiles” or “heroMap.tilesets”:  
phaser.js:74771 Uncaught TypeError: Cannot read property ‘source’ of undefined  
at StaticTilemapLayer.upload (phaser.js:74771)  
at StaticTilemapLayerWebGLRenderer [as renderWebGL] (phaser.js:122959)  
at WebGLRenderer.render (phaser.js:65133)  
at CameraManager.render (phaser.js:114533)  
at Systems.render (phaser.js:27184)  
at SceneManager.render (phaser.js:46818)  
at Game.step (phaser.js:109346)  
at TimeStep.step (phaser.js:106091)  
at step (phaser.js:66488)

error when passing in “…allTiles”:  
Uncaught TypeError: Cannot read property ‘tileWidth’ of undefined  
at Tilemap.createStaticLayer (phaser.js:77513)  
at Scene.create (index.js:63)  
at SceneManager.create (phaser.js:46843)  
at SceneManager.loadComplete (phaser.js:46737)  
at LoaderPlugin.emit (phaser.js:2011)  
at LoaderPlugin.loadComplete (phaser.js:89330)  
at LoaderPlugin.fileProcessComplete (phaser.js:89289)  
at ImageFile.onProcessComplete (phaser.js:4068)  
at Image.data.onload (phaser.js:7389)

---

<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:** [March 14, 2020, 8:29pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/4 "2020-03-14T20:29:53Z")

</div>

Switch to Phaser v3.22.0.

If you use `allTiles`, you have to create it **after** all the tilesets, otherwise it will be `[undefined, undefined, …]`.

---

<div class="post-metadata">

**Author:** ![malinda-lin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/malinda-lin/32/2975_2.png) [@malinda-lin](https://phaser.discourse.group/u/malinda-lin)\
**Post date:** [March 14, 2020, 8:39pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/5 "2020-03-14T20:39:13Z")

</div>

I reinstalled : npm install phaser@3.22.0  
I moved allTiles to under the last tile created  
(I was using heroMap.tilesets which is an array of all the tilesets so it didn’t matter if allTiles was [undefined,…] )

Still getting the error : Uncaught TypeError: Cannot read property ‘source’ of undefined

in phaser.js the error occurs at line 74771 var width = tileset.image.source[0].width;

It seems to me that this method isn’t able to take an array of tilesets

---

<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:** [March 14, 2020, 8:47pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/6 "2020-03-14T20:47:45Z")

</div>

Check Phaser version in console. It worked for me with `allTiles`.

---

<div class="post-metadata">

**Author:** ![malinda-lin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/malinda-lin/32/2975_2.png) [@malinda-lin](https://phaser.discourse.group/u/malinda-lin)\
**Post date:** [March 14, 2020, 9:06pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/7 "2020-03-14T21:06:01Z")

</div>

What do you mean when you say it worked? Phaser version is correct but not sure why it says v3.11 in the browser.  
Thank you so much for helping me btw.

 ![Screen Shot 2020-03-14 at 4.57.52 PM](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/4/48379e9e9cb47da1a33690162c422d194b788393.png) ![Screen Shot 2020-03-14 at 5.01.02 PM](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/d/d0fd9b2b2c8bd49cf691208af119e3aabea2358d.png) ![Screen Shot 2020-03-14 at 5.01.36 PM](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/3/36c2c5f6e2ce9444744dd42c7db9b5144f5b7557.png)

---

<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:** [March 14, 2020, 9:59pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/8 "2020-03-14T21:59:36Z")

</div>

In index.html use

```javascript
<script src="./node_modules/phaser/dist/phaser.js"></script>

```

---

<div class="post-metadata">

**Author:** ![malinda-lin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/malinda-lin/32/2975_2.png) [@malinda-lin](https://phaser.discourse.group/u/malinda-lin)\
**Post date:** [March 14, 2020, 10:23pm UTC](https://phaser.discourse.group/t/unable-to-pass-array-of-tilesets-to-createdynamiclayer-not-createstaticlayer/5505/9 "2020-03-14T22:23:37Z")

</div>

Thank you so much! That did it.
