Skip to content

Commit d59f772

Browse files
committed
Tilemap.getTileset is a new method that will return a Tileset based on its name.
1 parent 53b57cc commit d59f772

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

src/tilemaps/Tilemap.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,10 @@ var Tilemap = new Class({
718718
* @method Phaser.Tilemaps.Tilemap#createStaticLayer
719719
* @since 3.0.0
720720
*
721-
* @param {(integer|string)} layerID - The layer array index value, or if a string is given, the
722-
* layer name from Tiled.
723-
* @param {Phaser.Tilemaps.Tileset} tileset - The tileset the new layer will use.
724-
* @param {number} x - The x position to place the layer in the world. If not specified, it will
725-
* default to the layer offset from Tiled or 0.
726-
* @param {number} y - The y position to place the layer in the world. If not specified, it will
727-
* default to the layer offset from Tiled or 0.
721+
* @param {(integer|string)} layerID - The layer array index value, or if a string is given, the layer name from Tiled.
722+
* @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.
723+
* @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.
724+
* @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.
728725
*
729726
* @return {?Phaser.Tilemaps.StaticTilemapLayer} Returns the new layer was created, or null if it failed.
730727
*/
@@ -749,17 +746,6 @@ var Tilemap = new Class({
749746

750747
this.currentLayerIndex = index;
751748

752-
// Make sure that all the LayerData and the tiles have the correct tile size. They usually
753-
// are, but wouldn't match if you try to load a 2x or 4x res tileset when the map was made
754-
// with a 1x res tileset.
755-
756-
/*
757-
if (layerData.tileWidth !== tileset.tileWidth || layerData.tileHeight !== tileset.tileHeight)
758-
{
759-
this.setLayerTileSize(tileset.tileWidth, tileset.tileHeight, index);
760-
}
761-
*/
762-
763749
// Default the x/y position to match Tiled layer offset, if it exists.
764750
if (x === undefined && this.layers[index].x) { x = this.layers[index].x; }
765751
if (y === undefined && this.layers[index].y) { y = this.layers[index].y; }
@@ -1305,6 +1291,23 @@ var Tilemap = new Class({
13051291
return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer);
13061292
},
13071293

1294+
/**
1295+
* Gets the Tileset that has the given `name`, or null if an invalid `name` is given.
1296+
*
1297+
* @method Phaser.Tilemaps.Tilemap#getTileset
1298+
* @since 3.14.0
1299+
*
1300+
* @param {string} name - The name of the Tileset to get.
1301+
*
1302+
* @return {?Phaser.Tilemaps.Tileset} The Tileset, or `null` if no matching named tileset was found.
1303+
*/
1304+
getTileset: function (name)
1305+
{
1306+
var index = this.getIndex(this.tilesets, name);
1307+
1308+
return (index !== null) ? this.tilesets[index] : null;
1309+
},
1310+
13081311
/**
13091312
* Gets the index of the Tileset within this.tilesets that has the given `name`, or null if an
13101313
* invalid `name` is given.

0 commit comments

Comments
 (0)