Skip to content

Commit 95d4651

Browse files
committed
Dynamic Layers support multiple tilesets now
1 parent 0d5b209 commit 95d4651

1 file changed

Lines changed: 16 additions & 30 deletions

File tree

src/tilemaps/Tilemap.js

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -433,24 +433,20 @@ var Tilemap = new Class({
433433
},
434434

435435
/**
436-
* Creates a new and empty DynamicTilemapLayer. The currently selected layer in the map is set
437-
* to this new layer.
436+
* Creates a new and empty DynamicTilemapLayer. The currently selected layer in the map is set to this new layer.
438437
*
439438
* @method Phaser.Tilemaps.Tilemap#createBlankDynamicLayer
440439
* @since 3.0.0
441440
*
442441
* @param {string} name - The name of this layer. Must be unique within the map.
443-
* @param {Phaser.Tilemaps.Tileset} tileset - The tileset the new layer will use.
442+
* @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.
444443
* @param {number} [x=0] - The world x position where the top left of this layer will be placed.
445444
* @param {number} [y=0] - The world y position where the top left of this layer will be placed.
446-
* @param {integer} [width] - The width of the layer in tiles. If not specified, it will default
447-
* to the map's width.
448-
* @param {integer} [height] - The height of the layer in tiles. If not specified, it will default
449-
* to the map's height.
450-
* @param {integer} [tileWidth] - The width of the tiles the layer uses for calculations. If not
451-
* specified, it will default to the map's tileWidth.
452-
* @param {integer} [tileHeight] - The height of the tiles the layer uses for calculations. If not
453-
* specified, it will default to the map's tileHeight.
445+
* @param {integer} [width] - The width of the layer in tiles. If not specified, it will default to the map's width.
446+
* @param {integer} [height] - The height of the layer in tiles. If not specified, it will default to the map's height.
447+
* @param {integer} [tileWidth] - The width of the tiles the layer uses for calculations. If not specified, it will default to the map's tileWidth.
448+
* @param {integer} [tileHeight] - The height of the tiles the layer uses for calculations. If not specified, it will default to the map's tileHeight.
449+
*
454450
* @return {?Phaser.Tilemaps.DynamicTilemapLayer} Returns the new layer was created, or null if it failed.
455451
*/
456452
createBlankDynamicLayer: function (name, tileset, x, y, width, height, tileWidth, tileHeight)
@@ -466,7 +462,7 @@ var Tilemap = new Class({
466462

467463
if (index !== null)
468464
{
469-
console.warn('Cannot create blank layer: layer with matching name already exists ' + name);
465+
console.warn('Invalid Tilemap Layer ID: ' + name);
470466
return null;
471467
}
472468

@@ -493,6 +489,7 @@ var Tilemap = new Class({
493489
}
494490

495491
this.layers.push(layerData);
492+
496493
this.currentLayerIndex = this.layers.length - 1;
497494

498495
var dynamicLayer = new DynamicTilemapLayer(this.scene, this, this.currentLayerIndex, tileset, x, y);
@@ -518,13 +515,10 @@ var Tilemap = new Class({
518515
* @method Phaser.Tilemaps.Tilemap#createDynamicLayer
519516
* @since 3.0.0
520517
*
521-
* @param {(integer|string)} layerID - The layer array index value, or if a string is given, the
522-
* layer name from Tiled.
523-
* @param {Phaser.Tilemaps.Tileset} tileset - The tileset the new layer will use.
524-
* @param {number} x - The x position to place the layer in the world. If not specified, it will
525-
* default to the layer offset from Tiled or 0.
526-
* @param {number} y - The y position to place the layer in the world. If not specified, it will
527-
* default to the layer offset from Tiled or 0.
518+
* @param {(integer|string)} layerID - The layer array index value, or if a string is given, the layer name from Tiled.
519+
* @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.
520+
* @param {number} x - The x position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0.
521+
* @param {number} y - The y position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0.
528522
*
529523
* @return {?Phaser.Tilemaps.DynamicTilemapLayer} Returns the new layer was created, or null if it failed.
530524
*/
@@ -534,7 +528,7 @@ var Tilemap = new Class({
534528

535529
if (index === null)
536530
{
537-
console.warn('Cannot create Tilemap Layer, invalid ID: ' + layerID);
531+
console.warn('Invalid Tilemap Layer ID: ' + layerID);
538532
return null;
539533
}
540534

@@ -543,21 +537,13 @@ var Tilemap = new Class({
543537
// Check for an associated static or dynamic tilemap layer
544538
if (layerData.tilemapLayer)
545539
{
546-
console.warn('Cannot create Tilemap Layer. ID: ' + layerID + ' already in use');
540+
console.warn('Tilemap Layer ID already exists:' + layerID);
547541
return null;
548542
}
549543

550544
this.currentLayerIndex = index;
551545

552-
// Make sure that all the LayerData & the tiles have the correct tile size. They usually
553-
// are, but wouldn't match if you try to load a 2x or 4x res tileset when the map was made
554-
// with a 1x res tileset.
555-
if (layerData.tileWidth !== tileset.tileWidth || layerData.tileHeight !== tileset.tileHeight)
556-
{
557-
this.setLayerTileSize(tileset.tileWidth, tileset.tileHeight, index);
558-
}
559-
560-
// Default the x/y position to match Tiled layer offset, if it exists.
546+
// Default the x/y position to match Tiled layer offset, if it exists.
561547
if (x === undefined && this.layers[index].x) { x = this.layers[index].x; }
562548
if (y === undefined && this.layers[index].y) { y = this.layers[index].y; }
563549

0 commit comments

Comments
 (0)