Skip to content

Commit d92c7bf

Browse files
committed
Added setTilesets method.
1 parent d59f772 commit d92c7bf

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

src/tilemaps/staticlayer/StaticTilemapLayer.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var Utils = require('../../renderer/webgl/Utils');
4545
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs.
4646
* @param {Phaser.Tilemaps.Tilemap} tilemap - The Tilemap this layer is a part of.
4747
* @param {integer} layerIndex - The index of the LayerData associated with this layer.
48-
* @param {(Phaser.Tilemaps.Tileset|Phaser.Tilemaps.Tileset[])} tileset - The tileset, or an array of tilesets, used to render this layer.
48+
* @param {(string|string[]|Phaser.Tilemaps.Tileset|Phaser.Tilemaps.Tileset[])} tileset - The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object.
4949
* @param {number} [x=0] - The world x position where the top left of this layer will be placed.
5050
* @param {number} [y=0] - The world y position where the top left of this layer will be placed.
5151
*/
@@ -122,10 +122,10 @@ var StaticTilemapLayer = new Class({
122122
* As of Phaser 3.14 this property is now an array of Tileset objects, previously it was a single reference.
123123
*
124124
* @name Phaser.Tilemaps.StaticTilemapLayer#tileset
125-
* @type {(Phaser.Tilemaps.Tileset)}
125+
* @type {Phaser.Tilemaps.Tileset[]}
126126
* @since 3.0.0
127127
*/
128-
this.tileset = (Array.isArray(tileset)) ? tileset : [ tileset ];
128+
this.tileset = [];
129129

130130
/**
131131
* Used internally by the Canvas renderer.
@@ -351,6 +351,7 @@ var StaticTilemapLayer = new Class({
351351
*/
352352
this.gidMap = [];
353353

354+
this.setTilesets(tileset);
354355
this.setAlpha(this.layer.alpha);
355356
this.setPosition(x, y);
356357
this.setOrigin();
@@ -370,6 +371,47 @@ var StaticTilemapLayer = new Class({
370371
}
371372
},
372373

374+
/**
375+
* Populates the internal `tileset` array with the Tileset references this Layer requires for rendering.
376+
*
377+
* @method Phaser.Tilemaps.StaticTilemapLayer#setTilesets
378+
* @private
379+
* @since 3.14.0
380+
*
381+
* @param {(string|string[]|Phaser.Tilemaps.Tileset|Phaser.Tilemaps.Tileset[])} tileset - The tileset, or an array of tilesets, used to render this layer. Can be a string or a Tileset object.
382+
*/
383+
setTilesets: function (tilesets)
384+
{
385+
var setList = [];
386+
var map = this.tilemap;
387+
388+
if (!Array.isArray(tilesets))
389+
{
390+
tilesets = [ tilesets ];
391+
}
392+
393+
for (var i = 0; i < tilesets.length; i++)
394+
{
395+
var key = tilesets[i];
396+
397+
if (typeof key === 'string')
398+
{
399+
var tileset = map.getTileset(key);
400+
401+
if (tileset)
402+
{
403+
setList.push(tileset);
404+
}
405+
}
406+
else
407+
{
408+
setList.push(key);
409+
}
410+
}
411+
412+
this.tileset = setList;
413+
},
414+
373415
/**
374416
* Parses the tilesets that this Layer uses and constructs the
375417
* tileset index map used during Canvas rendering.

0 commit comments

Comments
 (0)