2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2023-03-26 16:34:25 +00:00
|
|
|
var BuildTilesetIndex = require('./parsers/tiled/BuildTilesetIndex');
|
2018-02-07 17:10:01 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-02-07 22:46:07 +00:00
|
|
|
var DegToRad = require('../math/DegToRad');
|
|
|
|
var Formats = require('./Formats');
|
2020-10-12 12:31:30 +00:00
|
|
|
var GetFastValue = require('../utils/object/GetFastValue');
|
2017-11-17 19:16:39 +00:00
|
|
|
var LayerData = require('./mapdata/LayerData');
|
2021-05-13 20:23:16 +00:00
|
|
|
var ObjectHelper = require('./ObjectHelper');
|
2020-12-14 09:48:29 +00:00
|
|
|
var ORIENTATION = require('./const/ORIENTATION_CONST');
|
2018-02-07 22:46:07 +00:00
|
|
|
var Rotate = require('../math/Rotate');
|
2019-04-08 14:45:16 +00:00
|
|
|
var SpliceOne = require('../utils/array/SpliceOne');
|
2020-10-12 12:31:30 +00:00
|
|
|
var Sprite = require('../gameobjects/sprite/Sprite');
|
2017-11-16 17:44:24 +00:00
|
|
|
var Tile = require('./Tile');
|
2018-02-07 22:46:07 +00:00
|
|
|
var TilemapComponents = require('./components');
|
2020-10-12 10:40:40 +00:00
|
|
|
var TilemapLayer = require('./TilemapLayer');
|
2018-02-07 22:46:07 +00:00
|
|
|
var Tileset = require('./Tileset');
|
2017-11-11 16:38:52 +00:00
|
|
|
|
2018-03-20 11:36:35 +00:00
|
|
|
/**
|
2023-01-17 14:19:36 +00:00
|
|
|
* A predicate, to test each element of the array.
|
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @callback TilemapFilterCallback
|
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} value - An object found in the filtered area.
|
|
|
|
* @param {number} index - The index of the object within the array.
|
|
|
|
* @param {Phaser.GameObjects.GameObject[]} array - An array of all the objects found.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2023-01-17 14:19:36 +00:00
|
|
|
* @return {boolean} A value that coerces to `true` to keep the element, or to `false` otherwise.
|
2018-03-20 11:36:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @callback TilemapFindCallback
|
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} value - An object found.
|
|
|
|
* @param {number} index - The index of the object within the array.
|
|
|
|
* @param {Phaser.GameObjects.GameObject[]} array - An array of all the objects found.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* @return {boolean} `true` if the callback should be invoked, otherwise `false`.
|
2018-03-20 11:36:35 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* A Tilemap is a container for Tilemap data. This isn't a display object, rather, it holds data
|
|
|
|
* about the map and allows you to add tilesets and tilemap layers to it. A map can have one or
|
2020-10-12 10:40:40 +00:00
|
|
|
* more tilemap layers, which are the display objects that actually render the tiles.
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* The Tilemap data can be parsed from a Tiled JSON file, a CSV file or a 2D array. Tiled is a free
|
2018-02-07 15:27:21 +00:00
|
|
|
* software package specifically for creating tile maps, and is available from:
|
|
|
|
* http://www.mapeditor.org
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* As of Phaser 3.50.0 the Tilemap API now supports the following types of map:
|
|
|
|
*
|
|
|
|
* 1) Orthogonal
|
|
|
|
* 2) Isometric
|
|
|
|
* 3) Hexagonal
|
|
|
|
* 4) Staggered
|
|
|
|
*
|
|
|
|
* Prior to this release, only orthogonal maps were supported.
|
|
|
|
*
|
|
|
|
* Another large change in 3.50 was the consolidation of Tilemap Layers. Previously, you created
|
|
|
|
* either a Static or Dynamic Tilemap Layer. However, as of 3.50 the features of both have been
|
|
|
|
* merged and the API simplified, so now there is just the single `TilemapLayer` class.
|
|
|
|
*
|
|
|
|
* A Tilemap has handy methods for getting and manipulating the tiles within a layer, allowing
|
|
|
|
* you to build or modify the tilemap data at runtime.
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
|
|
|
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a
|
2020-10-12 10:40:40 +00:00
|
|
|
* TilemapLayer may have its own unique tile size that overrides this.
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
2019-10-23 20:56:35 +00:00
|
|
|
* As of Phaser 3.21.0, if your tilemap includes layer groups (a feature of Tiled 1.2.0+) these
|
2020-10-12 10:40:40 +00:00
|
|
|
* will be traversed and the following properties will impact children:
|
|
|
|
*
|
|
|
|
* - Opacity (blended with parent) and visibility (parent overrides child)
|
2019-10-23 20:56:35 +00:00
|
|
|
* - Vertical and horizontal offset
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
2019-10-23 20:56:35 +00:00
|
|
|
* The grouping hierarchy is not preserved and all layers will be flattened into a single array.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
2019-10-23 20:56:35 +00:00
|
|
|
* Group layers are parsed during Tilemap construction but are discarded after parsing so dynamic
|
|
|
|
* layers will NOT continue to be affected by a parent.
|
|
|
|
*
|
|
|
|
* To avoid duplicate layer names, a layer that is a child of a group layer will have its parent
|
|
|
|
* group name prepended with a '/'. For example, consider a group called 'ParentGroup' with a
|
|
|
|
* child called 'Layer 1'. In the Tilemap object, 'Layer 1' will have the name
|
|
|
|
* 'ParentGroup/Layer 1'.
|
|
|
|
*
|
2018-02-07 15:27:21 +00:00
|
|
|
* @class Tilemap
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Tilemaps
|
2018-02-07 15:27:21 +00:00
|
|
|
* @constructor
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @param {Phaser.Scene} scene - The Scene to which this Tilemap belongs.
|
|
|
|
* @param {Phaser.Tilemaps.MapData} mapData - A MapData instance containing Tilemap data.
|
2018-02-07 15:27:21 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
var Tilemap = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-11-17 21:55:12 +00:00
|
|
|
function Tilemap (scene, mapData)
|
2017-11-11 16:38:52 +00:00
|
|
|
{
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.scene = scene;
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* The base width of a tile in pixels. Note that individual layers may have a different tile
|
|
|
|
* width.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#tileWidth
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.tileWidth = mapData.tileWidth;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The base height of a tile in pixels. Note that individual layers may have a different
|
|
|
|
* tile height.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#tileHeight
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.tileHeight = mapData.tileHeight;
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* The width of the map (in tiles).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#width
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.width = mapData.width;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the map (in tiles).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#height
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.height = mapData.height;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#orientation
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.orientation = mapData.orientation;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
2018-08-21 16:59:28 +00:00
|
|
|
/**
|
|
|
|
* The render (draw) order of the map data (as specified in Tiled), usually 'right-down'.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* The draw orders are:
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* right-down
|
|
|
|
* left-down
|
|
|
|
* right-up
|
|
|
|
* left-up
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* This can be changed via the `setRenderOrder` method.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.Tilemap#renderOrder
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.12.0
|
|
|
|
*/
|
|
|
|
this.renderOrder = mapData.renderOrder;
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* The format of the map data.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#format
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.format = mapData.format;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The version of the map data (as specified in Tiled, usually 1).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#version
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.version = mapData.version;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Map specific properties as specified in Tiled.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#properties
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.properties = mapData.properties;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The width of the map in pixels based on width * tileWidth.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#widthInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.widthInPixels = mapData.widthInPixels;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the map in pixels based on height * tileHeight.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#heightInPixels
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.heightInPixels = mapData.heightInPixels;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* A collection of Images, as parsed from Tiled map data.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#imageCollections
|
|
|
|
* @type {Phaser.Tilemaps.ImageCollection[]}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-24 14:21:09 +00:00
|
|
|
this.imageCollections = mapData.imageCollections;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of Tiled Image Layers.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#images
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-24 15:15:02 +00:00
|
|
|
this.images = mapData.images;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* An array of Tilemap layer data.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#layers
|
|
|
|
* @type {Phaser.Tilemaps.LayerData[]}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.layers = mapData.layers;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
2023-03-26 16:34:25 +00:00
|
|
|
/**
|
|
|
|
* Master list of tiles -> x, y, index in tileset.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.Tilemap#tiles
|
|
|
|
* @type {array}
|
|
|
|
* @since 3.60.0
|
|
|
|
* @see Phaser.Tilemaps.Parsers.Tiled.BuildTilesetIndex
|
|
|
|
*/
|
|
|
|
this.tiles = mapData.tiles;
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* An array of Tilesets used in the map.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#tilesets
|
|
|
|
* @type {Phaser.Tilemaps.Tileset[]}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.tilesets = mapData.tilesets;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2018-01-27 14:27:56 +00:00
|
|
|
* An array of ObjectLayer instances parsed from Tiled object layers.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#objects
|
|
|
|
* @type {Phaser.Tilemaps.ObjectLayer[]}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-11 16:38:52 +00:00
|
|
|
this.objects = mapData.objects;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The index of the currently selected LayerData object.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#currentLayerIndex
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 21:05:11 +00:00
|
|
|
this.currentLayerIndex = 0;
|
2020-09-19 08:56:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The length of the horizontal sides of the hexagon.
|
2020-10-02 10:57:37 +00:00
|
|
|
* Only used for hexagonal orientation Tilemaps.
|
2020-10-02 09:30:08 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.Tilemap#hexSideLength
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2020-10-02 09:30:08 +00:00
|
|
|
* @since 3.50.0
|
2020-09-19 08:56:05 +00:00
|
|
|
*/
|
|
|
|
this.hexSideLength = mapData.hexSideLength;
|
|
|
|
|
2020-10-02 10:53:23 +00:00
|
|
|
var orientation = this.orientation;
|
|
|
|
|
2020-09-19 08:56:05 +00:00
|
|
|
/**
|
2020-10-02 10:53:23 +00:00
|
|
|
* Functions used to handle world to tile, and tile to world, conversion.
|
|
|
|
* Cached here for internal use by public methods such as `worldToTileXY`, etc.
|
|
|
|
*
|
|
|
|
* @name Phaser.Tilemaps.Tilemap#_convert
|
|
|
|
* @private
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.50.0
|
2020-09-19 08:56:05 +00:00
|
|
|
*/
|
2020-10-02 10:53:23 +00:00
|
|
|
this._convert = {
|
|
|
|
WorldToTileXY: TilemapComponents.GetWorldToTileXYFunction(orientation),
|
|
|
|
WorldToTileX: TilemapComponents.GetWorldToTileXFunction(orientation),
|
|
|
|
WorldToTileY: TilemapComponents.GetWorldToTileYFunction(orientation),
|
|
|
|
TileToWorldXY: TilemapComponents.GetTileToWorldXYFunction(orientation),
|
|
|
|
TileToWorldX: TilemapComponents.GetTileToWorldXFunction(orientation),
|
2022-11-28 18:31:20 +00:00
|
|
|
TileToWorldY: TilemapComponents.GetTileToWorldYFunction(orientation),
|
|
|
|
GetTileCorners: TilemapComponents.GetTileCornersFunction(orientation)
|
2020-10-02 10:53:23 +00:00
|
|
|
};
|
2017-11-11 16:38:52 +00:00
|
|
|
},
|
|
|
|
|
2018-08-21 16:59:28 +00:00
|
|
|
/**
|
|
|
|
* Sets the rendering (draw) order of the tiles in this map.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* The default is 'right-down', meaning it will order the tiles starting from the top-left,
|
|
|
|
* drawing to the right and then moving down to the next row.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* The draw orders are:
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* 0 = right-down
|
|
|
|
* 1 = left-down
|
|
|
|
* 2 = right-up
|
|
|
|
* 3 = left-up
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* Setting the render order does not change the tiles or how they are stored in the layer,
|
|
|
|
* it purely impacts the order in which they are rendered.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-08-21 16:59:28 +00:00
|
|
|
* You can provide either an integer (0 to 3), or the string version of the order.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* Calling this method _after_ creating Tilemap Layers will **not** automatically
|
2018-08-21 16:59:28 +00:00
|
|
|
* update them to use the new render order. If you call this method after creating layers, use their
|
|
|
|
* own `setRenderOrder` methods to change them as needed.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setRenderOrder
|
|
|
|
* @since 3.12.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|string)} renderOrder - The render (draw) order value. Either an integer between 0 and 3, or a string: 'right-down', 'left-down', 'right-up' or 'left-up'.
|
2018-08-21 16:59:28 +00:00
|
|
|
*
|
|
|
|
* @return {this} This Tilemap object.
|
|
|
|
*/
|
|
|
|
setRenderOrder: function (renderOrder)
|
|
|
|
{
|
|
|
|
var orders = [ 'right-down', 'left-down', 'right-up', 'left-up' ];
|
|
|
|
|
|
|
|
if (typeof renderOrder === 'number')
|
|
|
|
{
|
|
|
|
renderOrder = orders[renderOrder];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (orders.indexOf(renderOrder) > -1)
|
|
|
|
{
|
|
|
|
this.renderOrder = renderOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Adds an image to the map to be used as a tileset. A single map may use multiple tilesets.
|
|
|
|
* Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled
|
|
|
|
* editor.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#addTilesetImage
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {string} tilesetName - The name of the tileset as specified in the map data.
|
|
|
|
* @param {string} [key] - The key of the Phaser.Cache image used for this tileset. If
|
2018-04-03 16:30:15 +00:00
|
|
|
* `undefined` or `null` it will look for an image with a key matching the tilesetName parameter.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [tileWidth] - The width of the tile (in pixels) in the Tileset Image. If not
|
2017-11-30 00:54:29 +00:00
|
|
|
* given it will default to the map's tileWidth value, or the tileWidth specified in the Tiled
|
|
|
|
* JSON file.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [tileHeight] - The height of the tiles (in pixels) in the Tileset Image. If
|
2017-11-30 00:54:29 +00:00
|
|
|
* not given it will default to the map's tileHeight value, or the tileHeight specified in the
|
|
|
|
* Tiled JSON file.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [tileMargin] - The margin around the tiles in the sheet (in pixels). If not
|
2017-11-30 00:54:29 +00:00
|
|
|
* specified, it will default to 0 or the value specified in the Tiled JSON file.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [tileSpacing] - The spacing between each the tile in the sheet (in pixels).
|
2017-11-30 00:54:29 +00:00
|
|
|
* If not specified, it will default to 0 or the value specified in the Tiled JSON file.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [gid=0] - If adding multiple tilesets to a blank map, specify the starting
|
2017-11-30 00:54:29 +00:00
|
|
|
* GID this set will use here.
|
2023-02-21 02:41:39 +00:00
|
|
|
* @param {object} [tileOffset={x: 0, y: 0}] - Tile texture drawing offset.
|
|
|
|
* If not specified, it will default to {0, 0}
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
|
|
|
* @return {?Phaser.Tilemaps.Tileset} Returns the Tileset object that was created or updated, or null if it
|
2017-11-30 00:54:29 +00:00
|
|
|
* failed.
|
|
|
|
*/
|
2023-02-21 02:41:39 +00:00
|
|
|
addTilesetImage: function (tilesetName, key, tileWidth, tileHeight, tileMargin, tileSpacing, gid, tileOffset)
|
2017-11-11 16:38:52 +00:00
|
|
|
{
|
|
|
|
if (tilesetName === undefined) { return null; }
|
|
|
|
if (key === undefined || key === null) { key = tilesetName; }
|
|
|
|
|
|
|
|
if (!this.scene.sys.textures.exists(key))
|
|
|
|
{
|
2018-09-27 10:33:58 +00:00
|
|
|
console.warn('Invalid Tileset Image: ' + key);
|
2017-11-11 16:38:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var texture = this.scene.sys.textures.get(key);
|
|
|
|
|
|
|
|
var index = this.getTilesetIndex(tilesetName);
|
|
|
|
|
2018-01-18 00:30:22 +00:00
|
|
|
if (index === null && this.format === Formats.TILED_JSON)
|
2017-11-11 16:38:52 +00:00
|
|
|
{
|
2018-09-27 10:33:58 +00:00
|
|
|
console.warn('No data found for Tileset: ' + tilesetName);
|
2017-11-11 16:38:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-09-27 10:33:58 +00:00
|
|
|
var tileset = this.tilesets[index];
|
|
|
|
|
|
|
|
if (tileset)
|
2017-11-11 16:38:52 +00:00
|
|
|
{
|
2018-09-27 10:33:58 +00:00
|
|
|
tileset.setTileSize(tileWidth, tileHeight);
|
|
|
|
tileset.setSpacing(tileMargin, tileSpacing);
|
|
|
|
tileset.setImage(texture);
|
|
|
|
|
|
|
|
return tileset;
|
2017-11-11 16:38:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 18:52:34 +00:00
|
|
|
if (tileWidth === undefined) { tileWidth = this.tileWidth; }
|
|
|
|
if (tileHeight === undefined) { tileHeight = this.tileHeight; }
|
2017-11-18 21:40:27 +00:00
|
|
|
if (tileMargin === undefined) { tileMargin = 0; }
|
|
|
|
if (tileSpacing === undefined) { tileSpacing = 0; }
|
|
|
|
if (gid === undefined) { gid = 0; }
|
2023-02-21 02:41:39 +00:00
|
|
|
if (tileOffset === undefined) { tileOffset = {x: 0, y: 0} }
|
2017-11-11 16:38:52 +00:00
|
|
|
|
2023-02-21 02:41:39 +00:00
|
|
|
tileset = new Tileset(tilesetName, gid, tileWidth, tileHeight, tileMargin, tileSpacing, undefined, undefined, tileOffset);
|
2018-09-27 10:33:58 +00:00
|
|
|
|
2017-11-18 21:40:27 +00:00
|
|
|
tileset.setImage(texture);
|
2018-09-27 10:33:58 +00:00
|
|
|
|
2017-11-18 21:40:27 +00:00
|
|
|
this.tilesets.push(tileset);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2023-03-26 16:34:25 +00:00
|
|
|
this.tiles = BuildTilesetIndex(this);
|
|
|
|
|
2017-11-11 16:38:52 +00:00
|
|
|
return tileset;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-09-28 13:32:36 +00:00
|
|
|
* Copies the tiles in the source rectangular area to a new destination (all specified in tile
|
|
|
|
* coordinates) within the layer. This copies all tile properties & recalculates collision
|
|
|
|
* information in the destination region.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2018-09-28 13:32:36 +00:00
|
|
|
* If no layer specified, the map's current layer is used. This cannot be applied to StaticTilemapLayers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#copy
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} srcTileX - The x coordinate of the area to copy from, in tiles, not pixels.
|
|
|
|
* @param {number} srcTileY - The y coordinate of the area to copy from, in tiles, not pixels.
|
|
|
|
* @param {number} width - The width of the area to copy, in tiles, not pixels.
|
|
|
|
* @param {number} height - The height of the area to copy, in tiles, not pixels.
|
|
|
|
* @param {number} destTileX - The x coordinate of the area to copy to, in tiles, not pixels.
|
|
|
|
* @param {number} destTileY - The y coordinate of the area to copy to, in tiles, not pixels.
|
2018-09-28 13:32:36 +00:00
|
|
|
* @param {boolean} [recalculateFaces=true] - `true` if the faces data should be recalculated.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
|
|
|
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
if (layer !== null)
|
|
|
|
{
|
2018-02-07 22:46:07 +00:00
|
|
|
TilemapComponents.Copy(
|
|
|
|
srcTileX, srcTileY,
|
|
|
|
width, height,
|
|
|
|
destTileX, destTileY,
|
|
|
|
recalculateFaces, layer
|
|
|
|
);
|
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2017-11-30 00:54:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Creates a new and empty Tilemap Layer. The currently selected layer in the map is set to this new layer.
|
|
|
|
*
|
|
|
|
* Prior to v3.50.0 this method was called `createBlankDynamicLayer`.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#createBlankLayer
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {string} name - The name of this layer. Must be unique within the map.
|
2018-09-27 12:09:40 +00:00
|
|
|
* @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.
|
2018-06-27 02:33:35 +00:00
|
|
|
* @param {number} [x=0] - The world x position where the top left of this layer will be placed.
|
|
|
|
* @param {number} [y=0] - The world y position where the top left of this layer will be placed.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [width] - The width of the layer in tiles. If not specified, it will default to the map's width.
|
|
|
|
* @param {number} [height] - The height of the layer in tiles. If not specified, it will default to the map's height.
|
|
|
|
* @param {number} [tileWidth] - The width of the tiles the layer uses for calculations. If not specified, it will default to the map's tileWidth.
|
|
|
|
* @param {number} [tileHeight] - The height of the tiles the layer uses for calculations. If not specified, it will default to the map's tileHeight.
|
2018-12-01 19:40:17 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {?Phaser.Tilemaps.TilemapLayer} Returns the new layer that was created, or `null` if it failed.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2020-10-12 10:40:40 +00:00
|
|
|
createBlankLayer: function (name, tileset, x, y, width, height, tileWidth, tileHeight)
|
2017-11-17 01:08:58 +00:00
|
|
|
{
|
2017-11-16 17:44:24 +00:00
|
|
|
if (x === undefined) { x = 0; }
|
|
|
|
if (y === undefined) { y = 0; }
|
2019-06-06 09:29:28 +00:00
|
|
|
if (width === undefined) { width = this.width; }
|
|
|
|
if (height === undefined) { height = this.height; }
|
|
|
|
if (tileWidth === undefined) { tileWidth = this.tileWidth; }
|
|
|
|
if (tileHeight === undefined) { tileHeight = this.tileHeight; }
|
2017-11-16 17:44:24 +00:00
|
|
|
|
|
|
|
var index = this.getLayerIndex(name);
|
|
|
|
|
|
|
|
if (index !== null)
|
|
|
|
{
|
2018-09-27 12:09:40 +00:00
|
|
|
console.warn('Invalid Tilemap Layer ID: ' + name);
|
2017-11-17 01:08:58 +00:00
|
|
|
return null;
|
2017-11-16 17:44:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 19:16:39 +00:00
|
|
|
var layerData = new LayerData({
|
|
|
|
name: name,
|
|
|
|
tileWidth: tileWidth,
|
|
|
|
tileHeight: tileHeight,
|
|
|
|
width: width,
|
2020-09-19 08:56:05 +00:00
|
|
|
height: height,
|
|
|
|
orientation: this.orientation
|
2017-11-17 19:16:39 +00:00
|
|
|
});
|
2017-11-16 17:44:24 +00:00
|
|
|
|
|
|
|
var row;
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 17:44:24 +00:00
|
|
|
for (var tileY = 0; tileY < height; tileY++)
|
|
|
|
{
|
|
|
|
row = [];
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 17:44:24 +00:00
|
|
|
for (var tileX = 0; tileX < width; tileX++)
|
|
|
|
{
|
2018-02-07 22:46:07 +00:00
|
|
|
row.push(new Tile(layerData, -1, tileX, tileY, tileWidth, tileHeight, this.tileWidth, this.tileHeight));
|
2017-11-16 17:44:24 +00:00
|
|
|
}
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 19:16:39 +00:00
|
|
|
layerData.data.push(row);
|
2017-11-16 17:44:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 19:16:39 +00:00
|
|
|
this.layers.push(layerData);
|
2018-09-27 12:09:40 +00:00
|
|
|
|
2017-11-16 17:44:24 +00:00
|
|
|
this.currentLayerIndex = this.layers.length - 1;
|
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
var layer = new TilemapLayer(this.scene, this, this.currentLayerIndex, tileset, x, y);
|
2018-08-21 16:59:28 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
layer.setRenderOrder(this.renderOrder);
|
2018-08-21 16:59:28 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
this.scene.sys.displayList.add(layer);
|
2017-11-17 21:55:12 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
return layer;
|
2017-11-16 17:44:24 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Creates a new Tilemap Layer that renders the LayerData associated with the given
|
2017-11-30 00:54:29 +00:00
|
|
|
* `layerID`. The currently selected layer in the map is set to this new layer.
|
|
|
|
*
|
|
|
|
* The `layerID` is important. If you've created your map in Tiled then you can get this by
|
|
|
|
* looking in Tiled and looking at the layer name. Or you can open the JSON file it exports and
|
|
|
|
* look at the layers[].name value. Either way it must match.
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* Prior to v3.50.0 this method was called `createDynamicLayer`.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#createLayer
|
2018-02-07 22:46:07 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|string)} layerID - The layer array index value, or if a string is given, the layer name from Tiled.
|
2018-09-27 12:09:40 +00:00
|
|
|
* @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.
|
2019-05-22 17:18:54 +00:00
|
|
|
* @param {number} [x=0] - The x position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0.
|
|
|
|
* @param {number} [y=0] - The y position to place the layer in the world. If not specified, it will default to the layer offset from Tiled or 0.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {?Phaser.Tilemaps.TilemapLayer} Returns the new layer was created, or null if it failed.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2020-10-12 10:40:40 +00:00
|
|
|
createLayer: function (layerID, tileset, x, y)
|
2017-11-30 00:54:29 +00:00
|
|
|
{
|
|
|
|
var index = this.getLayerIndex(layerID);
|
|
|
|
|
|
|
|
if (index === null)
|
|
|
|
{
|
2018-09-27 12:09:40 +00:00
|
|
|
console.warn('Invalid Tilemap Layer ID: ' + layerID);
|
2019-11-18 16:08:36 +00:00
|
|
|
|
2019-10-23 20:56:35 +00:00
|
|
|
if (typeof layerID === 'string')
|
|
|
|
{
|
2021-11-16 01:54:54 +00:00
|
|
|
console.warn('Valid tilelayer names: %o', this.getTileLayerNames());
|
2019-10-23 20:56:35 +00:00
|
|
|
}
|
2019-11-18 16:08:36 +00:00
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var layerData = this.layers[index];
|
|
|
|
|
2021-12-07 17:30:49 +00:00
|
|
|
// Check for an associated tilemap layer
|
2017-11-30 00:54:29 +00:00
|
|
|
if (layerData.tilemapLayer)
|
|
|
|
{
|
2018-09-27 12:09:40 +00:00
|
|
|
console.warn('Tilemap Layer ID already exists:' + layerID);
|
2017-11-30 00:54:29 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentLayerIndex = index;
|
|
|
|
|
2018-09-27 12:09:40 +00:00
|
|
|
// Default the x/y position to match Tiled layer offset, if it exists.
|
2019-06-06 09:43:46 +00:00
|
|
|
|
|
|
|
if (x === undefined)
|
2017-11-30 00:54:29 +00:00
|
|
|
{
|
2019-06-06 09:43:46 +00:00
|
|
|
x = layerData.x;
|
2017-11-30 00:54:29 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 09:43:46 +00:00
|
|
|
if (y === undefined)
|
|
|
|
{
|
|
|
|
y = layerData.y;
|
|
|
|
}
|
2017-11-30 00:54:29 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
var layer = new TilemapLayer(this.scene, this, index, tileset, x, y);
|
2018-08-21 16:59:28 +00:00
|
|
|
|
|
|
|
layer.setRenderOrder(this.renderOrder);
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
this.scene.sys.displayList.add(layer);
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
},
|
|
|
|
|
2017-11-29 04:40:48 +00:00
|
|
|
/**
|
2020-10-12 12:31:30 +00:00
|
|
|
* This method will iterate through all of the objects defined in a Tiled Object Layer and then
|
|
|
|
* convert the matching results into Phaser Game Objects (by default, Sprites)
|
2017-11-29 04:40:48 +00:00
|
|
|
*
|
2021-05-13 20:23:16 +00:00
|
|
|
* Objects are matched on one of 4 criteria: The Object ID, the Object GID, the Object Name, or the Object Type.
|
2020-10-12 12:31:30 +00:00
|
|
|
*
|
|
|
|
* Within Tiled, Object IDs are unique per Object. Object GIDs, however, are shared by all objects
|
2021-05-13 20:23:16 +00:00
|
|
|
* using the same image. Finally, Object Names and Types are strings and the same name can be used on multiple
|
|
|
|
* Objects in Tiled, they do not have to be unique; Names are specific to Objects while Types can be inherited
|
|
|
|
* from Object GIDs using the same image.
|
2020-10-12 12:31:30 +00:00
|
|
|
*
|
|
|
|
* You set the configuration parameter accordingly, based on which type of criteria you wish
|
|
|
|
* to match against. For example, to convert all items on an Object Layer with a `gid` of 26:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* createFromObjects(layerName, {
|
|
|
|
* gid: 26
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Or, to convert objects with the name 'bonus':
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* createFromObjects(layerName, {
|
|
|
|
* name: 'bonus'
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Or, to convert an object with a specific id:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* createFromObjects(layerName, {
|
|
|
|
* id: 9
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*
|
2021-05-13 20:23:16 +00:00
|
|
|
* You should only specify either `id`, `gid`, `name`, `type`, or none of them. Do not add more than
|
2020-10-12 12:31:30 +00:00
|
|
|
* one criteria to your config. If you do not specify any criteria, then _all_ objects in the
|
|
|
|
* Object Layer will be converted.
|
|
|
|
*
|
2023-02-15 21:40:17 +00:00
|
|
|
* By default this method will convert Objects into {@link Phaser.GameObjects.Sprite} instances, but you can override
|
2020-10-12 12:31:30 +00:00
|
|
|
* this by providing your own class type:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* createFromObjects(layerName, {
|
|
|
|
* gid: 26,
|
|
|
|
* classType: Coin
|
|
|
|
* });
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* This will convert all Objects with a gid of 26 into your custom `Coin` class. You can pass
|
2023-02-15 21:40:17 +00:00
|
|
|
* any class type here, but it _must_ extend {@link Phaser.GameObjects.GameObject} as its base class.
|
2020-10-12 12:31:30 +00:00
|
|
|
* Your class will always be passed 1 parameter: `scene`, which is a reference to either the Scene
|
2021-09-14 16:10:09 +00:00
|
|
|
* specified in the config object or, if not given, the Scene to which this Tilemap belongs. The
|
2023-02-15 21:40:17 +00:00
|
|
|
* class must have {@link Phaser.GameObjects.Components.Transform#setPosition setPosition} and
|
|
|
|
* {@link Phaser.GameObjects.Components.Texture#setTexture setTexture} methods.
|
2020-10-12 12:31:30 +00:00
|
|
|
*
|
2023-02-15 21:40:17 +00:00
|
|
|
* Custom properties on the Object are copied onto any existing properties on the Game Object, so you can use this as an easy
|
|
|
|
* way to configure properties from within the map editor. For example giving an Object a
|
2020-10-12 12:31:30 +00:00
|
|
|
* property of `alpha: 0.5` in Tiled will be reflected in the Game Object that is created.
|
|
|
|
*
|
2023-02-15 21:40:17 +00:00
|
|
|
* Custom properties that do not exist on the Game Object are set in the
|
|
|
|
* Game Object's {@link Phaser.GameObjects.GameObject#data data store}.
|
|
|
|
*
|
|
|
|
* When `useTileset` is `true` (the default), Tile Objects will inherit the texture and any tile properties
|
|
|
|
* from the tileset, and the local tile ID will be used as the texture frame. For the frame selection to work
|
|
|
|
* you need to load the tileset texture as a spritesheet so its frame names match the local tile IDs.
|
|
|
|
*
|
|
|
|
* For instance, a tileset tile
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* { id: 3, type: 'treadmill', speed: 4 }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* with gid 19 and an object
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* { id: 7, gid: 19, speed: 5, rotation: 90 }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* will be interpreted as
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* { id: 7, gid: 19, speed: 5, rotation: 90, type: 'treadmill', texture: '[the tileset texture]', frame: 3 }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* You can suppress this behavior by setting the boolean `ignoreTileset` for each `config` that should ignore
|
2021-05-13 20:23:16 +00:00
|
|
|
* object gid tilesets.
|
|
|
|
*
|
2023-02-15 21:40:17 +00:00
|
|
|
* You can set a `container` property in the config. If given, the new Game Object will be added to
|
|
|
|
* the Container or Layer instance instead of the Scene.
|
|
|
|
*
|
|
|
|
* You can set named texture-`key` and texture-`frame` properties, which will be set on the new Game Object.
|
2020-10-12 12:31:30 +00:00
|
|
|
*
|
|
|
|
* Finally, you can provide an array of config objects, to convert multiple types of object in
|
|
|
|
* a single call:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* createFromObjects(layerName, [
|
|
|
|
* {
|
|
|
|
* gid: 26,
|
|
|
|
* classType: Coin
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* id: 9,
|
|
|
|
* classType: BossMonster
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* name: 'lava',
|
|
|
|
* classType: LavaTile
|
2021-05-13 20:23:16 +00:00
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* type: 'endzone',
|
|
|
|
* classType: Phaser.GameObjects.Zone
|
2020-10-12 12:31:30 +00:00
|
|
|
* }
|
|
|
|
* ]);
|
|
|
|
* ```
|
|
|
|
*
|
2021-09-23 15:02:52 +00:00
|
|
|
* The signature of this method changed significantly in v3.60.0. Prior to this, it did not take config objects.
|
2018-07-08 01:12:49 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#createFromObjects
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-10-12 12:31:30 +00:00
|
|
|
* @param {string} objectLayerName - The name of the Tiled object layer to create the Game Objects from.
|
|
|
|
* @param {Phaser.Types.Tilemaps.CreateFromObjectLayerConfig|Phaser.Types.Tilemaps.CreateFromObjectLayerConfig[]} config - A CreateFromObjects configuration object, or an array of them.
|
2021-09-23 15:02:52 +00:00
|
|
|
* @param {boolean} [useTileset=true] - True if objects that set gids should also search the underlying tile for properties and data.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 12:31:30 +00:00
|
|
|
* @return {Phaser.GameObjects.GameObject[]} An array containing the Game Objects that were created. Empty if invalid object layer, or no matching id/gid/name was found.
|
2017-11-29 04:40:48 +00:00
|
|
|
*/
|
2021-05-13 20:23:16 +00:00
|
|
|
createFromObjects: function (objectLayerName, config, useTileset)
|
2017-11-29 04:40:48 +00:00
|
|
|
{
|
2021-09-23 15:02:52 +00:00
|
|
|
if (useTileset === undefined) { useTileset = true; }
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
var results = [];
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
var objectLayer = this.getObjectLayer(objectLayerName);
|
2019-06-06 10:20:40 +00:00
|
|
|
|
2018-01-27 14:27:56 +00:00
|
|
|
if (!objectLayer)
|
2017-11-29 04:40:48 +00:00
|
|
|
{
|
2020-10-12 12:31:30 +00:00
|
|
|
console.warn('createFromObjects: Invalid objectLayerName given: ' + objectLayerName);
|
2019-11-18 16:08:36 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
return results;
|
|
|
|
}
|
2019-11-18 16:08:36 +00:00
|
|
|
|
2021-05-13 20:23:16 +00:00
|
|
|
var objectHelper = new ObjectHelper(useTileset ? this.tilesets : undefined);
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
if (!Array.isArray(config))
|
|
|
|
{
|
|
|
|
config = [ config ];
|
2017-11-29 04:40:48 +00:00
|
|
|
}
|
|
|
|
|
2018-01-27 14:27:56 +00:00
|
|
|
var objects = objectLayer.objects;
|
2017-11-29 13:35:26 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
for (var c = 0; c < config.length; c++)
|
2017-11-29 04:40:48 +00:00
|
|
|
{
|
2020-10-12 12:31:30 +00:00
|
|
|
var singleConfig = config[c];
|
|
|
|
|
|
|
|
var id = GetFastValue(singleConfig, 'id', null);
|
|
|
|
var gid = GetFastValue(singleConfig, 'gid', null);
|
|
|
|
var name = GetFastValue(singleConfig, 'name', null);
|
2021-05-13 20:23:16 +00:00
|
|
|
var type = GetFastValue(singleConfig, 'type', null);
|
|
|
|
objectHelper.enabled = !GetFastValue(singleConfig, 'ignoreTileset', null);
|
2020-10-12 12:31:30 +00:00
|
|
|
|
|
|
|
var obj;
|
|
|
|
var toConvert = [];
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
// Sweep to get all the objects we want to convert in this pass
|
|
|
|
for (var s = 0; s < objects.length; s++)
|
2017-11-29 04:40:48 +00:00
|
|
|
{
|
2020-10-12 12:31:30 +00:00
|
|
|
obj = objects[s];
|
|
|
|
|
|
|
|
if (
|
2021-05-13 20:23:16 +00:00
|
|
|
(id === null && gid === null && name === null && type === null) ||
|
2020-10-12 12:31:30 +00:00
|
|
|
(id !== null && obj.id === id) ||
|
|
|
|
(gid !== null && obj.gid === gid) ||
|
2021-05-13 20:23:16 +00:00
|
|
|
(name !== null && obj.name === name) ||
|
|
|
|
(type !== null && objectHelper.getTypeIncludingTile(obj) === type)
|
2020-10-12 12:31:30 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
toConvert.push(obj);
|
|
|
|
}
|
2017-11-29 04:40:48 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
// Now let's convert them ...
|
|
|
|
|
|
|
|
var classType = GetFastValue(singleConfig, 'classType', Sprite);
|
|
|
|
var scene = GetFastValue(singleConfig, 'scene', this.scene);
|
|
|
|
var container = GetFastValue(singleConfig, 'container', null);
|
|
|
|
var texture = GetFastValue(singleConfig, 'key', null);
|
|
|
|
var frame = GetFastValue(singleConfig, 'frame', null);
|
|
|
|
|
|
|
|
for (var i = 0; i < toConvert.length; i++)
|
2017-11-29 04:40:48 +00:00
|
|
|
{
|
2020-10-12 12:31:30 +00:00
|
|
|
obj = toConvert[i];
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
var sprite = new classType(scene);
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
sprite.setName(obj.name);
|
|
|
|
sprite.setPosition(obj.x, obj.y);
|
2021-05-13 20:23:16 +00:00
|
|
|
objectHelper.setTextureAndFrame(sprite, texture, frame, obj);
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
if (obj.width)
|
|
|
|
{
|
|
|
|
sprite.displayWidth = obj.width;
|
|
|
|
}
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
if (obj.height)
|
|
|
|
{
|
|
|
|
sprite.displayHeight = obj.height;
|
|
|
|
}
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2021-10-03 19:30:05 +00:00
|
|
|
if (this.orientation === ORIENTATION.ISOMETRIC)
|
|
|
|
{
|
2021-10-06 02:19:09 +00:00
|
|
|
var isometricRatio = this.tileWidth / this.tileHeight;
|
2021-10-03 19:30:05 +00:00
|
|
|
var isometricPosition = {
|
2021-10-03 19:35:02 +00:00
|
|
|
x: sprite.x - sprite.y,
|
2021-10-06 02:19:09 +00:00
|
|
|
y: (sprite.x + sprite.y) / isometricRatio
|
2021-10-03 19:35:02 +00:00
|
|
|
};
|
2021-10-03 19:30:05 +00:00
|
|
|
|
2021-10-03 19:35:02 +00:00
|
|
|
sprite.x = isometricPosition.x;
|
|
|
|
sprite.y = isometricPosition.y;
|
2021-10-03 19:30:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 18:08:32 +00:00
|
|
|
// Origin is (0, 1) for tile objects or (0, 0) for other objects in Tiled, so find the offset that matches the Sprites origin.
|
2020-10-12 12:31:30 +00:00
|
|
|
// Do not offset objects with zero dimensions (e.g. points).
|
2017-11-29 13:25:04 +00:00
|
|
|
var offset = {
|
2020-03-22 16:37:42 +00:00
|
|
|
x: sprite.originX * obj.width,
|
2021-07-22 18:08:32 +00:00
|
|
|
y: (sprite.originY - (obj.gid ? 1 : 0)) * obj.height
|
2017-11-29 13:25:04 +00:00
|
|
|
};
|
2017-11-29 04:40:48 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
// If the object is rotated, then the origin offset also needs to be rotated.
|
2017-11-29 04:40:48 +00:00
|
|
|
if (obj.rotation)
|
|
|
|
{
|
|
|
|
var angle = DegToRad(obj.rotation);
|
2020-10-12 12:31:30 +00:00
|
|
|
|
2017-11-29 04:40:48 +00:00
|
|
|
Rotate(offset, angle);
|
2020-10-12 12:31:30 +00:00
|
|
|
|
2017-11-29 04:40:48 +00:00
|
|
|
sprite.rotation = angle;
|
|
|
|
}
|
|
|
|
|
2017-11-29 13:25:04 +00:00
|
|
|
sprite.x += offset.x;
|
|
|
|
sprite.y += offset.y;
|
|
|
|
|
2017-11-29 04:40:48 +00:00
|
|
|
if (obj.flippedHorizontal !== undefined || obj.flippedVertical !== undefined)
|
|
|
|
{
|
|
|
|
sprite.setFlip(obj.flippedHorizontal, obj.flippedVertical);
|
|
|
|
}
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
if (!obj.visible)
|
|
|
|
{
|
|
|
|
sprite.visible = false;
|
|
|
|
}
|
2017-11-29 13:35:26 +00:00
|
|
|
|
2021-05-20 20:00:51 +00:00
|
|
|
objectHelper.setPropertiesFromTiledObject(sprite, obj);
|
2018-07-08 01:12:49 +00:00
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
if (container)
|
|
|
|
{
|
|
|
|
container.add(sprite);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scene.add.existing(sprite);
|
2018-07-08 01:12:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
results.push(sprite);
|
2017-11-29 04:40:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-12 12:31:30 +00:00
|
|
|
return results;
|
2017-11-29 04:40:48 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Creates a Sprite for every object matching the given tile indexes in the layer. You can
|
|
|
|
* optionally specify if each tile will be replaced with a new tile after the Sprite has been
|
|
|
|
* created. This is useful if you want to lay down special tiles in a level that are converted to
|
|
|
|
* Sprites, but want to replace the tile itself with a floor tile or similar once converted.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#createFromTiles
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|array)} indexes - The tile index, or array of indexes, to create Sprites from.
|
2022-12-19 11:28:40 +00:00
|
|
|
* @param {?(number|array)} replacements - The tile index, or array of indexes, to change a converted
|
2018-02-07 22:46:07 +00:00
|
|
|
* tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a
|
|
|
|
* one-to-one mapping with the indexes array.
|
2019-05-09 14:32:53 +00:00
|
|
|
* @param {Phaser.Types.GameObjects.Sprite.SpriteConfig} spriteConfig - The config object to pass into the Sprite creator (i.e. scene.make.sprite).
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Scene} [scene] - The Scene to create the Sprites within.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.GameObjects.Sprite[]} Returns an array of Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
|
|
|
createFromTiles: function (indexes, replacements, spriteConfig, scene, camera, layer)
|
2017-11-11 16:38:52 +00:00
|
|
|
{
|
2017-11-30 00:54:29 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
return TilemapComponents.CreateFromTiles(indexes, replacements, spriteConfig, scene, camera, layer);
|
2017-11-11 16:38:52 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Sets the tiles in the given rectangular area (in tile coordinates) of the layer with the
|
|
|
|
* specified index. Tiles will be set to collide if the given index is a colliding index.
|
|
|
|
* Collision information in the region will be recalculated.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* If no layer specified, the map's current layer is used.
|
|
|
|
* This cannot be applied to StaticTilemapLayers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#fill
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} index - The tile index to fill the area with.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {boolean} [recalculateFaces=true] - `true` if the faces data should be recalculated.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-26 15:19:57 +00:00
|
|
|
fill: function (index, tileX, tileY, width, height, recalculateFaces, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
return this;
|
|
|
|
},
|
2017-11-15 22:36:41 +00:00
|
|
|
|
2018-01-27 16:27:12 +00:00
|
|
|
/**
|
|
|
|
* For each object in the given object layer, run the given filter callback function. Any
|
2023-01-17 14:19:36 +00:00
|
|
|
* objects that pass the filter test (i.e. where the callback returns true) will be returned in a
|
2018-01-27 16:27:12 +00:00
|
|
|
* new array. Similar to Array.prototype.Filter in vanilla JS.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#filterObjects
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-16 15:02:27 +00:00
|
|
|
* @param {(Phaser.Tilemaps.ObjectLayer|string)} objectLayer - The name of an object layer (from Tiled) or an ObjectLayer instance.
|
|
|
|
* @param {TilemapFilterCallback} callback - The callback. Each object in the given area will be passed to this callback as the first and only parameter.
|
2018-01-27 16:27:12 +00:00
|
|
|
* @param {object} [context] - The context under which the callback should be run.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-09-23 11:59:03 +00:00
|
|
|
* @return {?Phaser.Types.Tilemaps.TiledObject[]} An array of object that match the search, or null if the objectLayer given was invalid.
|
2018-01-27 16:27:12 +00:00
|
|
|
*/
|
|
|
|
filterObjects: function (objectLayer, callback, context)
|
|
|
|
{
|
|
|
|
if (typeof objectLayer === 'string')
|
|
|
|
{
|
|
|
|
var name = objectLayer;
|
|
|
|
|
|
|
|
objectLayer = this.getObjectLayer(objectLayer);
|
|
|
|
|
|
|
|
if (!objectLayer)
|
|
|
|
{
|
|
|
|
console.warn('No object layer found with the name: ' + name);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectLayer.objects.filter(callback, context);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* For each tile in the given rectangular area (in tile coordinates) of the layer, run the given
|
|
|
|
* filter callback function. Any tiles that pass the filter test (i.e. where the callback returns
|
|
|
|
* true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS.
|
|
|
|
* If no layer specified, the map's current layer is used.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#filterTiles
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @param {function} callback - The callback. Each tile in the given area will be passed to this
|
|
|
|
* callback as the first and only parameter. The callback should return true for tiles that pass the
|
|
|
|
* filter.
|
|
|
|
* @param {object} [context] - The context under which the callback should be run.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area to filter.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area to filter.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 02:49:24 +00:00
|
|
|
filterTiles: function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-29 02:49:24 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-29 02:49:24 +00:00
|
|
|
return TilemapComponents.FilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, layer);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Searches the entire map layer for the first tile matching the given index, then returns that Tile
|
|
|
|
* object. If no match is found, it returns null. The search starts from the top-left tile and
|
|
|
|
* continues horizontally until it hits the end of the row, then it drops down to the next column.
|
|
|
|
* If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to
|
|
|
|
* the top-left.
|
|
|
|
* If no layer specified, the map's current layer is used.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#findByIndex
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} index - The tile index value to search for.
|
|
|
|
* @param {number} [skip=0] - The number of times to skip a matching tile before returning.
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {boolean} [reverse=false] - If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 01:08:58 +00:00
|
|
|
findByIndex: function (findIndex, skip, reverse, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
return TilemapComponents.FindByIndex(findIndex, skip, reverse, layer);
|
|
|
|
},
|
|
|
|
|
2018-01-27 16:27:12 +00:00
|
|
|
/**
|
|
|
|
* Find the first object in the given object layer that satisfies the provided testing function.
|
|
|
|
* I.e. finds the first object for which `callback` returns true. Similar to
|
|
|
|
* Array.prototype.find in vanilla JS.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#findObject
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-04-16 15:02:27 +00:00
|
|
|
* @param {(Phaser.Tilemaps.ObjectLayer|string)} objectLayer - The name of an object layer (from Tiled) or an ObjectLayer instance.
|
|
|
|
* @param {TilemapFindCallback} callback - The callback. Each object in the given area will be passed to this callback as the first and only parameter.
|
2018-01-27 16:27:12 +00:00
|
|
|
* @param {object} [context] - The context under which the callback should be run.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-09-23 11:59:03 +00:00
|
|
|
* @return {?Phaser.Types.Tilemaps.TiledObject} An object that matches the search, or null if no object found.
|
2018-01-27 16:27:12 +00:00
|
|
|
*/
|
|
|
|
findObject: function (objectLayer, callback, context)
|
|
|
|
{
|
|
|
|
if (typeof objectLayer === 'string')
|
|
|
|
{
|
|
|
|
var name = objectLayer;
|
|
|
|
|
|
|
|
objectLayer = this.getObjectLayer(objectLayer);
|
|
|
|
|
|
|
|
if (!objectLayer)
|
|
|
|
{
|
|
|
|
console.warn('No object layer found with the name: ' + name);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return objectLayer.objects.find(callback, context) || null;
|
|
|
|
},
|
|
|
|
|
2017-12-01 19:46:27 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Find the first tile in the given rectangular area (in tile coordinates) of the layer that
|
|
|
|
* satisfies the provided testing function. I.e. finds the first tile for which `callback` returns
|
|
|
|
* true. Similar to Array.prototype.find in vanilla JS.
|
|
|
|
* If no layer specified, the maps current layer is used.
|
2017-12-01 19:46:27 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#findTile
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {FindTileCallback} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
|
2018-02-07 22:46:07 +00:00
|
|
|
* @param {object} [context] - The context under which the callback should be run.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area to search.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area to search.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The Tile layer to run the search on. If not provided will use the current layer.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tiles, or null if the layer given was invalid.
|
2017-12-01 19:46:27 +00:00
|
|
|
*/
|
|
|
|
findTile: function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-12-01 19:46:27 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-12-01 19:46:27 +00:00
|
|
|
return TilemapComponents.FindTile(callback, context, tileX, tileY, width, height, filteringOptions, layer);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* For each tile in the given rectangular area (in tile coordinates) of the layer, run the given
|
|
|
|
* callback. Similar to Array.prototype.forEach in vanilla JS.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* If no layer specified, the map's current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#forEachTile
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {EachTileCallback} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
|
2018-02-07 22:46:07 +00:00
|
|
|
* @param {object} [context] - The context under which the callback should be run.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area to search.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area to search.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The Tile layer to run the search on. If not provided will use the current layer.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-26 00:03:21 +00:00
|
|
|
forEachTile: function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
return this;
|
2017-11-15 22:36:41 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Gets the image layer index based on its name.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getImageIndex
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {string} name - The name of the image to get.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The index of the image in this tilemap, or null if not found.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-24 15:15:02 +00:00
|
|
|
getImageIndex: function (name)
|
|
|
|
{
|
|
|
|
return this.getIndex(this.images, name);
|
|
|
|
},
|
|
|
|
|
2019-10-23 20:56:35 +00:00
|
|
|
/**
|
|
|
|
* Return a list of all valid imagelayer names loaded in this Tilemap.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getImageLayerNames
|
|
|
|
* @since 3.21.0
|
|
|
|
*
|
2019-11-18 16:08:36 +00:00
|
|
|
* @return {string[]} Array of valid imagelayer names / IDs loaded into this Tilemap.
|
2019-10-23 20:56:35 +00:00
|
|
|
*/
|
|
|
|
getImageLayerNames: function ()
|
|
|
|
{
|
2019-11-18 16:08:36 +00:00
|
|
|
if (!this.images || !Array.isArray(this.images))
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.images.map(function (image)
|
|
|
|
{
|
|
|
|
return image.name;
|
|
|
|
});
|
2019-10-23 20:56:35 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Internally used. Returns the index of the object in one of the Tilemaps arrays whose name
|
2017-11-30 00:54:29 +00:00
|
|
|
* property matches the given `name`.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getIndex
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {array} location - The Tilemap array to search.
|
|
|
|
* @param {string} name - The name of the array element to get.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @return {number} The index of the element in the array, or null if not found.
|
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
getIndex: function (location, name)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < location.length; i++)
|
|
|
|
{
|
|
|
|
if (location[i].name === name)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-15 20:55:26 +00:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Gets the LayerData from `this.layers` that is associated with the given `layer`, or null if the layer is invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getLayer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The name of the layer from Tiled, the index of the layer in the map or Tilemap Layer. If not given will default to the maps current layer index.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @return {Phaser.Tilemaps.LayerData} The corresponding LayerData within this.layers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
getLayer: function (layer)
|
|
|
|
{
|
|
|
|
var index = this.getLayerIndex(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:45:16 +00:00
|
|
|
return (index !== null) ? this.layers[index] : null;
|
2017-11-15 20:55:26 +00:00
|
|
|
},
|
|
|
|
|
2018-01-27 14:27:56 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Gets the ObjectLayer from `this.objects` that has the given `name`, or null if no ObjectLayer is found with that name.
|
2018-01-27 14:27:56 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getObjectLayer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-01-27 14:27:56 +00:00
|
|
|
* @param {string} [name] - The name of the object layer from Tiled.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {?Phaser.Tilemaps.ObjectLayer} The corresponding `ObjectLayer` within `this.objects`, or null.
|
2018-01-27 14:27:56 +00:00
|
|
|
*/
|
|
|
|
getObjectLayer: function (name)
|
|
|
|
{
|
|
|
|
var index = this.getIndex(this.objects, name);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
return (index !== null) ? this.objects[index] : null;
|
2018-01-27 14:27:56 +00:00
|
|
|
},
|
|
|
|
|
2019-10-23 20:56:35 +00:00
|
|
|
/**
|
|
|
|
* Return a list of all valid objectgroup names loaded in this Tilemap.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getObjectLayerNames
|
|
|
|
* @since 3.21.0
|
|
|
|
*
|
2019-11-18 16:08:36 +00:00
|
|
|
* @return {string[]} Array of valid objectgroup names / IDs loaded into this Tilemap.
|
2019-10-23 20:56:35 +00:00
|
|
|
*/
|
|
|
|
getObjectLayerNames: function ()
|
|
|
|
{
|
2019-11-18 16:08:36 +00:00
|
|
|
if (!this.objects || !Array.isArray(this.objects))
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.objects.map(function (object)
|
|
|
|
{
|
|
|
|
return object.name;
|
|
|
|
});
|
2019-10-23 20:56:35 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Gets the LayerData index of the given `layer` within this.layers, or null if an invalid
|
|
|
|
* `layer` is given.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getLayerIndex
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The name of the layer from Tiled, the index of the layer in the map or a Tilemap Layer. If not given will default to the map's current layer index.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The LayerData index within this.layers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
getLayerIndex: function (layer)
|
|
|
|
{
|
|
|
|
if (layer === undefined)
|
|
|
|
{
|
2017-11-15 21:05:11 +00:00
|
|
|
return this.currentLayerIndex;
|
2017-11-15 20:55:26 +00:00
|
|
|
}
|
|
|
|
else if (typeof layer === 'string')
|
|
|
|
{
|
|
|
|
return this.getLayerIndexByName(layer);
|
|
|
|
}
|
|
|
|
else if (typeof layer === 'number' && layer < this.layers.length)
|
|
|
|
{
|
|
|
|
return layer;
|
|
|
|
}
|
2020-10-12 10:40:40 +00:00
|
|
|
else if (layer instanceof TilemapLayer)
|
2017-11-15 20:55:26 +00:00
|
|
|
{
|
|
|
|
return layer.layerIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Gets the index of the LayerData within this.layers that has the given `name`, or null if an
|
|
|
|
* invalid `name` is given.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getLayerIndexByName
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {string} name - The name of the layer to get.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The LayerData index within this.layers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
getLayerIndexByName: function (name)
|
|
|
|
{
|
|
|
|
return this.getIndex(this.layers, name);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Gets a tile at the given tile coordinates from the given layer.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTileAt
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - X position to get the tile from (given in tile units, not pixels).
|
|
|
|
* @param {number} tileY - Y position to get the tile from (given in tile units, not pixels).
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [nonNull] - If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-16 19:09:07 +00:00
|
|
|
getTileAt: function (tileX, tileY, nonNull, layer)
|
2017-11-15 19:50:56 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-15 19:50:56 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, layer);
|
2017-11-15 20:55:26 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Gets a tile at the given world coordinates from the given layer.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTileAtWorldXY
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @param {number} worldX - X position to get the tile from (given in pixels)
|
|
|
|
* @param {number} worldY - Y position to get the tile from (given in pixels)
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [nonNull] - If true, function won't return null for empty tiles, but a Tile object with an index of -1.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 13:58:33 +00:00
|
|
|
getTileAtWorldXY: function (worldX, worldY, nonNull, camera, layer)
|
2017-11-16 19:27:52 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2019-06-29 19:13:15 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, layer);
|
2017-11-16 19:27:52 +00:00
|
|
|
},
|
|
|
|
|
2019-10-23 20:56:35 +00:00
|
|
|
/**
|
|
|
|
* Return a list of all valid tilelayer names loaded in this Tilemap.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTileLayerNames
|
|
|
|
* @since 3.21.0
|
|
|
|
*
|
2019-11-22 17:46:26 +00:00
|
|
|
* @return {string[]} Array of valid tilelayer names / IDs loaded into this Tilemap.
|
2019-10-23 20:56:35 +00:00
|
|
|
*/
|
|
|
|
getTileLayerNames: function ()
|
|
|
|
{
|
2019-11-18 16:08:36 +00:00
|
|
|
if (!this.layers || !Array.isArray(this.layers))
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.layers.map(function (layer)
|
|
|
|
{
|
|
|
|
return layer.name;
|
|
|
|
});
|
2019-10-23 20:56:35 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Gets the tiles in the given rectangular area (in tile coordinates) of the layer.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTilesWithin
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-26 00:03:21 +00:00
|
|
|
getTilesWithin: function (tileX, tileY, width, height, filteringOptions, layer)
|
2017-11-15 22:36:41 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-15 22:36:41 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, filteringOptions, layer);
|
2017-11-15 22:36:41 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Gets the tiles that overlap with the given shape in the given layer. The shape must be a Circle,
|
|
|
|
* Line, Rectangle or Triangle. The shape should be in world coordinates.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTilesWithinShape
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-03-20 15:11:33 +00:00
|
|
|
* @param {(Phaser.Geom.Circle|Phaser.Geom.Line|Phaser.Geom.Rectangle|Phaser.Geom.Triangle)} shape - A shape in world (pixel) coordinates
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when factoring in which tiles to return.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-26 13:55:44 +00:00
|
|
|
getTilesWithinShape: function (shape, filteringOptions, camera, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-26 13:55:44 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-26 13:55:44 +00:00
|
|
|
return TilemapComponents.GetTilesWithinShape(shape, filteringOptions, camera, layer);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Gets the tiles in the given rectangular area (in world coordinates) of the layer.
|
2020-10-12 10:40:40 +00:00
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTilesWithinWorldXY
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The world x coordinate for the top-left of the area.
|
|
|
|
* @param {number} worldY - The world y coordinate for the top-left of the area.
|
|
|
|
* @param {number} width - The width of the area.
|
|
|
|
* @param {number} height - The height of the area.
|
2019-05-09 11:39:19 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.FilteringOptions} [filteringOptions] - Optional filters to apply when getting the tiles.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when factoring in which tiles to return.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile[]} Returns an array of Tiles, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-26 00:03:21 +00:00
|
|
|
getTilesWithinWorldXY: function (worldX, worldY, width, height, filteringOptions, camera, layer)
|
2017-11-25 14:42:19 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-25 14:42:19 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, layer);
|
2017-11-25 14:42:19 +00:00
|
|
|
},
|
|
|
|
|
2018-09-27 11:12:16 +00:00
|
|
|
/**
|
|
|
|
* Gets the Tileset that has the given `name`, or null if an invalid `name` is given.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTileset
|
|
|
|
* @since 3.14.0
|
|
|
|
*
|
|
|
|
* @param {string} name - The name of the Tileset to get.
|
|
|
|
*
|
|
|
|
* @return {?Phaser.Tilemaps.Tileset} The Tileset, or `null` if no matching named tileset was found.
|
|
|
|
*/
|
|
|
|
getTileset: function (name)
|
|
|
|
{
|
|
|
|
var index = this.getIndex(this.tilesets, name);
|
|
|
|
|
|
|
|
return (index !== null) ? this.tilesets[index] : null;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Gets the index of the Tileset within this.tilesets that has the given `name`, or null if an
|
|
|
|
* invalid `name` is given.
|
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTilesetIndex
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2017-11-30 00:54:29 +00:00
|
|
|
* @param {string} name - The name of the Tileset to get.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The Tileset index within this.tilesets.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
getTilesetIndex: function (name)
|
|
|
|
{
|
|
|
|
return this.getIndex(this.tilesets, name);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns
|
|
|
|
* false if there is no tile or if the tile at that location has an index of -1.
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#hasTileAt
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?boolean} Returns a boolean, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 21:28:15 +00:00
|
|
|
hasTileAt: function (tileX, tileY, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-15 21:28:15 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-15 21:28:15 +00:00
|
|
|
return TilemapComponents.HasTileAt(tileX, tileY, layer);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Checks if there is a tile at the given location (in world coordinates) in the given layer. Returns
|
|
|
|
* false if there is no tile or if the tile at that location has an index of -1.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#hasTileAtWorldXY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The x coordinate, in pixels.
|
|
|
|
* @param {number} worldY - The y coordinate, in pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when factoring in which tiles to return.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?boolean} Returns a boolean, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 13:58:33 +00:00
|
|
|
hasTileAtWorldXY: function (worldX, worldY, camera, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, layer);
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* The LayerData object that is currently selected in the map. You can set this property using
|
|
|
|
* any type supported by setLayer.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @name Phaser.Tilemaps.Tilemap#layer
|
|
|
|
* @type {Phaser.Tilemaps.LayerData}
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
layer: {
|
|
|
|
get: function ()
|
|
|
|
{
|
2017-11-15 21:05:11 +00:00
|
|
|
return this.layers[this.currentLayerIndex];
|
2017-11-15 20:55:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function (layer)
|
|
|
|
{
|
|
|
|
this.setLayer(layer);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Puts a tile at the given tile coordinates in the specified layer. You can pass in either an index
|
|
|
|
* or a Tile object. If you pass in a Tile, all attributes will be copied over to the specified
|
|
|
|
* location. If you pass in an index, only the index at the specified location will be changed.
|
|
|
|
* Collision information will be recalculated at the specified location.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#putTileAt
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|Phaser.Tilemaps.Tile)} tile - The index of this tile to set or a Tile object.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [recalculateFaces] - `true` if the faces data should be recalculated.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid or the coordinates were out of bounds.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
putTileAt: function (tile, tileX, tileY, recalculateFaces, layer)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.PutTileAt(tile, tileX, tileY, recalculateFaces, layer);
|
2017-11-16 19:09:07 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Puts a tile at the given world coordinates (pixels) in the specified layer. You can pass in either
|
|
|
|
* an index or a Tile object. If you pass in a Tile, all attributes will be copied over to the
|
|
|
|
* specified location. If you pass in an index, only the index at the specified location will be
|
|
|
|
* changed. Collision information will be recalculated at the specified location.
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#putTileAtWorldXY
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|Phaser.Tilemaps.Tile)} tile - The index of this tile to set or a Tile object.
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The x coordinate, in pixels.
|
|
|
|
* @param {number} worldY - The y coordinate, in pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [recalculateFaces] - `true` if the faces data should be recalculated.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
putTileAtWorldXY: function (tile, worldX, worldY, recalculateFaces, camera, layer)
|
2017-11-17 13:58:33 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer);
|
2017-11-17 13:58:33 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 03:59:11 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Puts an array of tiles or a 2D array of tiles at the given tile coordinates in the specified
|
|
|
|
* layer. The array can be composed of either tile indexes or Tile objects. If you pass in a Tile,
|
|
|
|
* all attributes will be copied over to the specified location. If you pass in an index, only the
|
|
|
|
* index at the specified location will be changed. Collision information will be recalculated
|
|
|
|
* within the region tiles were changed.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 03:59:11 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#putTilesAt
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number[]|number[][]|Phaser.Tilemaps.Tile[]|Phaser.Tilemaps.Tile[][])} tile - A row (array) or grid (2D array) of Tiles or tile indexes to place.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [recalculateFaces] - `true` if the faces data should be recalculated.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 03:59:11 +00:00
|
|
|
*/
|
|
|
|
putTilesAt: function (tilesArray, tileX, tileY, recalculateFaces, layer)
|
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-30 03:59:11 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.PutTilesAt(tilesArray, tileX, tileY, recalculateFaces, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-30 03:59:11 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the
|
2019-06-06 10:20:40 +00:00
|
|
|
* specified layer. Each tile will receive a new index. If an array of indexes is passed in, then
|
2018-02-07 22:46:07 +00:00
|
|
|
* those will be used for randomly assigning new tile indexes. If an array is not provided, the
|
|
|
|
* indexes found within the region (excluding -1) will be used for randomly assigning new tile
|
|
|
|
* indexes. This method only modifies tile indexes and does not change collision information.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#randomize
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:23:10 +00:00
|
|
|
* @param {number[]} [indexes] - An array of indexes to randomly draw from during randomization.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 19:22:30 +00:00
|
|
|
randomize: function (tileX, tileY, width, height, indexes, layer)
|
2017-11-16 02:06:07 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.Randomize(tileX, tileY, width, height, indexes, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-29 22:30:57 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Calculates interesting faces at the given tile coordinates of the specified layer. Interesting
|
|
|
|
* faces are used internally for optimizing collisions against tiles. This method is mostly used
|
|
|
|
* internally to optimize recalculating faces when only one tile has been changed.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-01-29 22:30:57 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#calculateFacesAt
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2018-01-29 22:30:57 +00:00
|
|
|
*/
|
|
|
|
calculateFacesAt: function (tileX, tileY, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2018-01-29 22:30:57 +00:00
|
|
|
TilemapComponents.CalculateFacesAt(tileX, tileY, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2018-01-29 22:30:57 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 22:46:07 +00:00
|
|
|
* Calculates interesting faces within the rectangular area specified (in tile coordinates) of the
|
|
|
|
* layer. Interesting faces are used internally for optimizing collisions against tiles. This method
|
|
|
|
* is mostly used internally.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#calculateFacesWithin
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
calculateFacesWithin: function (tileX, tileY, width, height, layer)
|
2017-11-21 02:06:49 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:45:16 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
TilemapComponents.CalculateFacesWithin(tileX, tileY, width, height, layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2019-04-08 14:45:16 +00:00
|
|
|
/**
|
|
|
|
* Removes the given TilemapLayer from this Tilemap without destroying it.
|
2019-06-29 19:13:15 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2019-04-08 14:45:16 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#removeLayer
|
|
|
|
* @since 3.17.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to be removed.
|
2019-04-08 14:45:16 +00:00
|
|
|
*
|
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
|
|
|
*/
|
|
|
|
removeLayer: function (layer)
|
|
|
|
{
|
|
|
|
var index = this.getLayerIndex(layer);
|
|
|
|
|
|
|
|
if (index !== null)
|
|
|
|
{
|
|
|
|
SpliceOne(this.layers, index);
|
2020-10-12 10:40:40 +00:00
|
|
|
|
2019-10-31 21:03:48 +00:00
|
|
|
for (var i = index; i < this.layers.length; i++)
|
|
|
|
{
|
|
|
|
if (this.layers[i].tilemapLayer)
|
|
|
|
{
|
|
|
|
this.layers[i].tilemapLayer.layerIndex--;
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 14:45:16 +00:00
|
|
|
|
|
|
|
if (this.currentLayerIndex === index)
|
|
|
|
{
|
|
|
|
this.currentLayerIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the given TilemapLayer and removes it from this Tilemap.
|
2019-06-29 19:13:15 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2019-04-08 14:45:16 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#destroyLayer
|
|
|
|
* @since 3.17.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to be destroyed.
|
2019-04-08 14:45:16 +00:00
|
|
|
*
|
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Returns this, or null if the layer given was invalid.
|
|
|
|
*/
|
|
|
|
destroyLayer: function (layer)
|
|
|
|
{
|
|
|
|
var index = this.getLayerIndex(layer);
|
|
|
|
|
|
|
|
if (index !== null)
|
|
|
|
{
|
|
|
|
layer = this.layers[index];
|
|
|
|
|
2022-11-17 14:34:46 +00:00
|
|
|
layer.tilemapLayer.destroy();
|
2019-04-08 14:45:16 +00:00
|
|
|
|
|
|
|
SpliceOne(this.layers, index);
|
|
|
|
|
|
|
|
if (this.currentLayerIndex === index)
|
|
|
|
{
|
|
|
|
this.currentLayerIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Removes all Tilemap Layers from this Tilemap and calls `destroy` on each of them.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 22:46:07 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#removeAllLayers
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {this} This Tilemap object.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 01:09:28 +00:00
|
|
|
removeAllLayers: function ()
|
|
|
|
{
|
2019-04-08 14:45:16 +00:00
|
|
|
var layers = this.layers;
|
|
|
|
|
|
|
|
for (var i = 0; i < layers.length; i++)
|
2017-11-30 00:54:29 +00:00
|
|
|
{
|
2019-04-08 14:45:16 +00:00
|
|
|
if (layers[i].tilemapLayer)
|
2017-11-30 00:54:29 +00:00
|
|
|
{
|
2019-04-08 14:59:48 +00:00
|
|
|
layers[i].tilemapLayer.destroy(false);
|
2017-11-30 00:54:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2019-04-08 14:45:16 +00:00
|
|
|
layers.length = 0;
|
|
|
|
|
2017-11-17 01:09:28 +00:00
|
|
|
this.currentLayerIndex = 0;
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 01:09:28 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2019-03-05 14:45:53 +00:00
|
|
|
/**
|
|
|
|
* Removes the given Tile, or an array of Tiles, from the layer to which they belong,
|
|
|
|
* and optionally recalculates the collision information.
|
2019-06-29 19:13:15 +00:00
|
|
|
*
|
2019-03-05 14:45:53 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#removeTile
|
2019-03-07 12:31:06 +00:00
|
|
|
* @since 3.17.0
|
2019-03-05 14:45:53 +00:00
|
|
|
*
|
|
|
|
* @param {(Phaser.Tilemaps.Tile|Phaser.Tilemaps.Tile[])} tiles - The Tile to remove, or an array of Tiles.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} [replaceIndex=-1] - After removing the Tile, insert a brand new Tile into its location with the given index. Leave as -1 to just remove the tile.
|
2019-03-05 14:45:53 +00:00
|
|
|
* @param {boolean} [recalculateFaces=true] - `true` if the faces data should be recalculated.
|
|
|
|
*
|
|
|
|
* @return {Phaser.Tilemaps.Tile[]} Returns an array of Tiles that were removed.
|
|
|
|
*/
|
|
|
|
removeTile: function (tiles, replaceIndex, recalculateFaces)
|
|
|
|
{
|
|
|
|
if (replaceIndex === undefined) { replaceIndex = -1; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
|
|
|
var removed = [];
|
|
|
|
|
|
|
|
if (!Array.isArray(tiles))
|
|
|
|
{
|
|
|
|
tiles = [ tiles ];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < tiles.length; i++)
|
|
|
|
{
|
|
|
|
var tile = tiles[i];
|
|
|
|
|
|
|
|
removed.push(this.removeTileAt(tile.x, tile.y, true, recalculateFaces, tile.tilemapLayer));
|
|
|
|
|
|
|
|
if (replaceIndex > -1)
|
|
|
|
{
|
|
|
|
this.putTileAt(replaceIndex, tile.x, tile.y, recalculateFaces, tile.tilemapLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Removes the tile at the given tile coordinates in the specified layer and updates the layers collision information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#removeTileAt
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [replaceWithNull] - If `true` (the default), this will replace the tile at the specified location with null instead of a Tile with an index of -1.
|
|
|
|
* @param {boolean} [recalculateFaces] - If `true` (the default), the faces data will be recalculated.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
2019-03-05 14:45:53 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns the Tile that was removed, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
removeTileAt: function (tileX, tileY, replaceWithNull, recalculateFaces, layer)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (replaceWithNull === undefined) { replaceWithNull = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer);
|
2017-11-16 19:09:07 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Removes the tile at the given world coordinates in the specified layer and updates the layers collision information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 22:46:07 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#removeTileAtWorldXY
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The x coordinate, in pixels.
|
|
|
|
* @param {number} worldY - The y coordinate, in pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [replaceWithNull] - If `true` (the default), this will replace the tile at the specified location with null instead of a Tile with an index of -1.
|
|
|
|
* @param {boolean} [recalculateFaces] - If `true` (the default), the faces data will be recalculated.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tile} Returns a Tile, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-22 01:18:34 +00:00
|
|
|
removeTileAtWorldXY: function (worldX, worldY, replaceWithNull, recalculateFaces, camera, layer)
|
2017-11-17 13:58:33 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (replaceWithNull === undefined) { replaceWithNull = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 22:46:07 +00:00
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer);
|
2017-11-17 13:58:33 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Draws a debug representation of the layer to the given Graphics object. This is helpful when you want to
|
2018-02-07 23:08:37 +00:00
|
|
|
* get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles
|
|
|
|
* are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation
|
|
|
|
* wherever you want on the screen.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2020-12-14 09:48:29 +00:00
|
|
|
* **Note:** This method currently only works with orthogonal tilemap layers.
|
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#renderDebug
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Graphics} graphics - The target Graphics object to draw upon.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.StyleConfig} [styleConfig] - An object specifying the colors to use for the debug drawing.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 15:05:53 +00:00
|
|
|
renderDebug: function (graphics, styleConfig, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2020-12-14 09:48:29 +00:00
|
|
|
if (this.orientation === ORIENTATION.ORTHOGONAL)
|
|
|
|
{
|
|
|
|
TilemapComponents.RenderDebug(graphics, styleConfig, layer);
|
|
|
|
}
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 15:05:53 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2019-04-08 15:05:12 +00:00
|
|
|
/**
|
|
|
|
* Draws a debug representation of all layers within this Tilemap to the given Graphics object.
|
2019-06-29 19:13:15 +00:00
|
|
|
*
|
2019-04-08 15:05:12 +00:00
|
|
|
* This is helpful when you want to get a quick idea of which of your tiles are colliding and which
|
|
|
|
* have interesting faces. The tiles are drawn starting at (0, 0) in the Graphics, allowing you to
|
|
|
|
* place the debug representation wherever you want on the screen.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#renderDebugFull
|
|
|
|
* @since 3.17.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Graphics} graphics - The target Graphics object to draw upon.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Types.Tilemaps.StyleConfig} [styleConfig] - An object specifying the colors to use for the debug drawing.
|
2019-04-08 15:05:12 +00:00
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @return {this} This Tilemap instance.
|
2019-04-08 15:05:12 +00:00
|
|
|
*/
|
|
|
|
renderDebugFull: function (graphics, styleConfig)
|
|
|
|
{
|
|
|
|
var layers = this.layers;
|
|
|
|
|
|
|
|
for (var i = 0; i < layers.length; i++)
|
|
|
|
{
|
|
|
|
TilemapComponents.RenderDebug(graphics, styleConfig, layers[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Scans the given rectangular area (given in tile coordinates) for tiles with an index matching
|
|
|
|
* `findIndex` and updates their index to match `newIndex`. This only modifies the index and does
|
|
|
|
* not change collision information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#replaceByIndex
|
|
|
|
* @since 3.0.0
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} findIndex - The index of the tile to search for.
|
|
|
|
* @param {number} newIndex - The index of the tile to replace it with.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 01:08:58 +00:00
|
|
|
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Sets collision on the given tile or tiles within a layer by index. You can pass in either a
|
|
|
|
* single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if
|
|
|
|
* collision will be enabled (true) or disabled (false).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setCollision
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|array)} indexes - Either a single tile index, or an array of tile indexes.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [collides] - If true it will enable collision. If false it will clear collision.
|
|
|
|
* @param {boolean} [recalculateFaces] - Whether or not to recalculate the tile faces after the update.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2019-10-02 14:15:18 +00:00
|
|
|
* @param {boolean} [updateLayer=true] - If true, updates the current tiles on the layer. Set to false if no tiles have been placed for significant performance boost.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2018-07-19 15:59:35 +00:00
|
|
|
setCollision: function (indexes, collides, recalculateFaces, layer, updateLayer)
|
2017-11-21 02:06:49 +00:00
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
if (updateLayer === undefined) { updateLayer = true; }
|
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-07-19 15:59:35 +00:00
|
|
|
TilemapComponents.SetCollision(indexes, collides, recalculateFaces, layer, updateLayer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Sets collision on a range of tiles in a layer whose index is between the specified `start` and
|
|
|
|
* `stop` (inclusive). Calling this with a start value of 10 and a stop value of 14 would set
|
|
|
|
* collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be
|
|
|
|
* enabled (true) or disabled (false).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#setCollisionBetween
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} start - The first index of the tile to be set for collision.
|
|
|
|
* @param {number} stop - The last index of the tile to be set for collision.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [collides] - If true it will enable collision. If false it will clear collision.
|
|
|
|
* @param {boolean} [recalculateFaces] - Whether or not to recalculate the tile faces after the update.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-21 02:06:49 +00:00
|
|
|
setCollisionBetween: function (start, stop, collides, recalculateFaces, layer)
|
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
TilemapComponents.SetCollisionBetween(start, stop, collides, recalculateFaces, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-23 15:05:37 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Sets collision on the tiles within a layer by checking tile properties. If a tile has a property
|
|
|
|
* that matches the given properties object, its collision flag will be set. The `collides`
|
|
|
|
* parameter controls if collision will be enabled (true) or disabled (false). Passing in
|
|
|
|
* `{ collides: true }` would update the collision flag on any tiles with a "collides" property that
|
|
|
|
* has a value of true. Any tile that doesn't have "collides" set to true will be ignored. You can
|
|
|
|
* also use an array of values, e.g. `{ types: ["stone", "lava", "sand" ] }`. If a tile has a
|
|
|
|
* "types" property that matches any of those values, its collision flag will be updated.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setCollisionByProperty
|
|
|
|
* @since 3.0.0
|
2018-01-23 15:05:37 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {object} properties - An object with tile properties and corresponding values that should be checked.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [collides] - If true it will enable collision. If false it will clear collision.
|
|
|
|
* @param {boolean} [recalculateFaces] - Whether or not to recalculate the tile faces after the update.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2018-01-23 15:05:37 +00:00
|
|
|
*/
|
|
|
|
setCollisionByProperty: function (properties, collides, recalculateFaces, layer)
|
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2018-01-23 15:05:37 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-01-23 15:05:37 +00:00
|
|
|
TilemapComponents.SetCollisionByProperty(properties, collides, recalculateFaces, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-01-23 15:05:37 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Sets collision on all tiles in the given layer, except for tiles that have an index specified in
|
|
|
|
* the given array. The `collides` parameter controls if collision will be enabled (true) or
|
2020-06-05 17:01:30 +00:00
|
|
|
* disabled (false). Tile indexes not currently in the layer are not affected.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setCollisionByExclusion
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-11-23 10:23:10 +00:00
|
|
|
* @param {number[]} indexes - An array of the tile indexes to not be counted for collision.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [collides] - If true it will enable collision. If false it will clear collision.
|
|
|
|
* @param {boolean} [recalculateFaces] - Whether or not to recalculate the tile faces after the update.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-21 02:06:49 +00:00
|
|
|
setCollisionByExclusion: function (indexes, collides, recalculateFaces, layer)
|
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
TilemapComponents.SetCollisionByExclusion(indexes, collides, recalculateFaces, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-01-23 15:40:59 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Sets collision on the tiles within a layer by checking each tiles collision group data
|
2018-02-07 23:08:37 +00:00
|
|
|
* (typically defined in Tiled within the tileset collision editor). If any objects are found within
|
2020-10-12 10:40:40 +00:00
|
|
|
* a tiles collision group, the tiles colliding information will be set. The `collides` parameter
|
2018-02-07 23:08:37 +00:00
|
|
|
* controls if collision will be enabled (true) or disabled (false).
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setCollisionFromCollisionGroup
|
|
|
|
* @since 3.0.0
|
2018-01-23 15:40:59 +00:00
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [collides] - If true it will enable collision. If false it will clear collision.
|
|
|
|
* @param {boolean} [recalculateFaces] - Whether or not to recalculate the tile faces after the update.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2018-01-23 15:40:59 +00:00
|
|
|
*/
|
|
|
|
setCollisionFromCollisionGroup: function (collides, recalculateFaces, layer)
|
|
|
|
{
|
2020-11-26 12:55:40 +00:00
|
|
|
if (collides === undefined) { collides = true; }
|
|
|
|
if (recalculateFaces === undefined) { recalculateFaces = true; }
|
|
|
|
|
2018-01-23 15:40:59 +00:00
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-01-23 15:40:59 +00:00
|
|
|
TilemapComponents.SetCollisionFromCollisionGroup(collides, recalculateFaces, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-01-23 15:40:59 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Sets a global collision callback for the given tile index within the layer. This will affect all
|
|
|
|
* tiles on this layer that have the same index. If a callback is already set for the tile index it
|
|
|
|
* will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile
|
2020-10-12 10:40:40 +00:00
|
|
|
* at a specific location on the map then see `setTileLocationCallback`.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setTileIndexCallback
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @param {(number|number[])} indexes - Either a single tile index, or an array of tile indexes to have a collision callback set for. All values should be integers.
|
2018-02-07 23:08:37 +00:00
|
|
|
* @param {function} callback - The callback that will be invoked when the tile is collided with.
|
|
|
|
* @param {object} callbackContext - The context under which the callback is called.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 13:53:04 +00:00
|
|
|
setTileIndexCallback: function (indexes, callback, callbackContext, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 13:53:04 +00:00
|
|
|
TilemapComponents.SetTileIndexCallback(indexes, callback, callbackContext, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 13:53:04 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2019-10-29 05:50:33 +00:00
|
|
|
* Sets a collision callback for the given rectangular area (in tile coordinates) within the layer.
|
2018-02-07 23:08:37 +00:00
|
|
|
* If a callback is already set for the tile index it will be replaced. Set the callback to null to
|
|
|
|
* remove it.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#setTileLocationCallback
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} tileY - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} width - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} height - How many tiles tall from the `tileY` index the area will be.
|
2018-02-07 23:08:37 +00:00
|
|
|
* @param {function} callback - The callback that will be invoked when the tile is collided with.
|
2018-04-16 15:02:27 +00:00
|
|
|
* @param {object} [callbackContext] - The context under which the callback is called.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 14:20:24 +00:00
|
|
|
setTileLocationCallback: function (tileX, tileY, width, height, callback, callbackContext, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 14:20:24 +00:00
|
|
|
TilemapComponents.SetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 14:20:24 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Sets the current layer to the LayerData associated with `layer`.
|
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#setLayer
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The name of the layer from Tiled, the index of the layer in the map or a TilemapLayer. If not given will default to the maps current layer index.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {this} This Tilemap object.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-15 20:55:26 +00:00
|
|
|
setLayer: function (layer)
|
|
|
|
{
|
|
|
|
var index = this.getLayerIndex(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-15 20:55:26 +00:00
|
|
|
if (index !== null)
|
|
|
|
{
|
2017-11-15 21:05:11 +00:00
|
|
|
this.currentLayerIndex = index;
|
2017-11-15 20:55:26 +00:00
|
|
|
}
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-15 20:55:26 +00:00
|
|
|
return this;
|
2017-11-16 02:06:07 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
|
|
|
* Sets the base tile size for the map. Note: this does not necessarily match the tileWidth and
|
2017-11-30 05:16:48 +00:00
|
|
|
* tileHeight for all layers. This also updates the base size on all tiles across all layers.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#setBaseTileSize
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileWidth - The width of the tiles the map uses for calculations.
|
|
|
|
* @param {number} tileHeight - The height of the tiles the map uses for calculations.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {this} This Tilemap object.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 18:52:34 +00:00
|
|
|
setBaseTileSize: function (tileWidth, tileHeight)
|
2017-11-17 01:09:28 +00:00
|
|
|
{
|
|
|
|
this.tileWidth = tileWidth;
|
|
|
|
this.tileHeight = tileHeight;
|
|
|
|
this.widthInPixels = this.width * tileWidth;
|
|
|
|
this.heightInPixels = this.height * tileHeight;
|
2017-11-30 00:54:29 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
// Update the base tile size on all layers & tiles
|
2017-11-30 05:16:48 +00:00
|
|
|
for (var i = 0; i < this.layers.length; i++)
|
|
|
|
{
|
2018-09-25 14:19:57 +00:00
|
|
|
this.layers[i].baseTileWidth = tileWidth;
|
|
|
|
this.layers[i].baseTileHeight = tileHeight;
|
2017-12-01 19:25:48 +00:00
|
|
|
|
2017-11-30 05:16:48 +00:00
|
|
|
var mapData = this.layers[i].data;
|
|
|
|
var mapWidth = this.layers[i].width;
|
|
|
|
var mapHeight = this.layers[i].height;
|
|
|
|
|
2018-12-13 11:07:20 +00:00
|
|
|
for (var row = 0; row < mapHeight; row++)
|
2017-11-30 05:16:48 +00:00
|
|
|
{
|
2018-12-13 11:07:20 +00:00
|
|
|
for (var col = 0; col < mapWidth; col++)
|
2017-11-30 05:16:48 +00:00
|
|
|
{
|
|
|
|
var tile = mapData[row][col];
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-30 05:16:48 +00:00
|
|
|
if (tile !== null)
|
|
|
|
{
|
|
|
|
tile.setSize(undefined, undefined, tileWidth, tileHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
return this;
|
2017-11-29 18:52:34 +00:00
|
|
|
},
|
2017-11-18 21:40:27 +00:00
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Sets the tile size for a specific `layer`. Note: this does not necessarily match the maps
|
2017-11-30 00:54:29 +00:00
|
|
|
* tileWidth and tileHeight for all layers. This will set the tile size for the layer and any
|
|
|
|
* tiles the layer has.
|
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#setLayerTileSize
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileWidth - The width of the tiles (in pixels) in the layer.
|
|
|
|
* @param {number} tileHeight - The height of the tiles (in pixels) in the layer.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The name of the layer from Tiled, the index of the layer in the map or a TilemapLayer. If not given will default to the maps current layer index.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {this} This Tilemap object.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-29 18:52:34 +00:00
|
|
|
setLayerTileSize: function (tileWidth, tileHeight, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-29 18:52:34 +00:00
|
|
|
if (layer === null) { return this; }
|
|
|
|
|
|
|
|
layer.tileWidth = tileWidth;
|
|
|
|
layer.tileHeight = tileHeight;
|
2017-11-18 21:40:27 +00:00
|
|
|
|
2017-11-29 18:52:34 +00:00
|
|
|
var mapData = layer.data;
|
|
|
|
var mapWidth = layer.width;
|
|
|
|
var mapHeight = layer.height;
|
2017-11-18 21:40:27 +00:00
|
|
|
|
2018-12-13 11:07:20 +00:00
|
|
|
for (var row = 0; row < mapHeight; row++)
|
2017-11-29 18:52:34 +00:00
|
|
|
{
|
2018-12-13 11:07:20 +00:00
|
|
|
for (var col = 0; col < mapWidth; col++)
|
2017-11-18 21:40:27 +00:00
|
|
|
{
|
2017-11-29 18:52:34 +00:00
|
|
|
var tile = mapData[row][col];
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2018-12-13 11:07:20 +00:00
|
|
|
if (tile !== null)
|
|
|
|
{
|
|
|
|
tile.setSize(tileWidth, tileHeight);
|
|
|
|
}
|
2017-11-18 21:40:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2017-11-17 01:09:28 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Shuffles the tiles in a rectangular region (specified in tile coordinates) within the given
|
|
|
|
* layer. It will only randomize the tiles in that area, so if they're all the same nothing will
|
|
|
|
* appear to have changed! This method only modifies tile indexes and does not change collision
|
|
|
|
* information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-02-07 23:08:37 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#shuffle
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-16 02:06:07 +00:00
|
|
|
shuffle: function (tileX, tileY, width, height, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.Shuffle(tileX, tileY, width, height, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-16 02:06:07 +00:00
|
|
|
return this;
|
2017-11-17 01:08:58 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Scans the given rectangular area (given in tile coordinates) for tiles with an index matching
|
|
|
|
* `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision
|
|
|
|
* information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#swapByIndex
|
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileA - First tile index.
|
|
|
|
* @param {number} tileB - Second tile index.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-17 01:08:58 +00:00
|
|
|
swapByIndex: function (indexA, indexB, tileX, tileY, width, height, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
return this;
|
2017-11-17 01:58:35 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the
|
|
|
|
* layers position, scale and scroll.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#tileToWorldX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?number} Returns a number, or null if the layer given was invalid.
|
2017-11-30 15:22:54 +00:00
|
|
|
*/
|
|
|
|
tileToWorldX: function (tileX, camera, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-30 15:22:54 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2020-10-02 10:53:23 +00:00
|
|
|
return this._convert.TileToWorldX(tileX, camera, layer);
|
2017-11-30 15:22:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-07 23:08:37 +00:00
|
|
|
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
|
|
|
|
* layers position, scale and scroll.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#tileToWorldY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2017-11-30 15:22:54 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?number} Returns a number, or null if the layer given was invalid.
|
2017-11-30 15:22:54 +00:00
|
|
|
*/
|
2021-06-30 13:21:13 +00:00
|
|
|
tileToWorldY: function (tileY, camera, layer)
|
2017-11-30 15:22:54 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2017-11-30 15:22:54 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:08:37 +00:00
|
|
|
|
2021-06-30 13:21:13 +00:00
|
|
|
return this._convert.TileToWorldY(tileY, camera, layer);
|
2017-11-30 15:22:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-07 23:12:55 +00:00
|
|
|
* Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
|
|
|
|
* layers position, scale and scroll. This will return a new Vector2 object or update the given
|
|
|
|
* `point` object.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-02-07 23:12:55 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#tileToWorldXY
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 15:22:54 +00:00
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
2020-10-12 10:40:40 +00:00
|
|
|
* @param {Phaser.Math.Vector2} [vec2] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:12:55 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {?Phaser.Math.Vector2} Returns a Vector2, or null if the layer given was invalid.
|
2017-11-30 15:22:54 +00:00
|
|
|
*/
|
2020-10-12 10:40:40 +00:00
|
|
|
tileToWorldXY: function (tileX, tileY, vec2, camera, layer)
|
2017-11-30 15:22:54 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2017-11-30 15:22:54 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
return this._convert.TileToWorldXY(tileX, tileY, vec2, camera, layer);
|
2017-11-30 15:22:54 +00:00
|
|
|
},
|
|
|
|
|
2022-11-28 18:31:20 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of Vector2s where each entry corresponds to the corner of the requested tile.
|
|
|
|
*
|
|
|
|
* The `tileX` and `tileY` parameters are in tile coordinates, not world coordinates.
|
|
|
|
*
|
|
|
|
* The corner coordinates are in world space, having factored in TilemapLayer scale, position
|
|
|
|
* and the camera, if given.
|
|
|
|
*
|
|
|
|
* The size of the array will vary based on the orientation of the map. For example an
|
|
|
|
* orthographic map will return an array of 4 vectors, where-as a hexagonal map will,
|
|
|
|
* of course, return an array of 6 corner vectors.
|
|
|
|
*
|
|
|
|
* If no layer is specified, the maps current layer is used.
|
|
|
|
*
|
|
|
|
* @method Phaser.Tilemaps.Tilemap#getTileCorners
|
|
|
|
* @since 3.60.0
|
|
|
|
*
|
|
|
|
* @param {number} tileX - The x coordinate, in tiles, not pixels.
|
|
|
|
* @param {number} tileY - The y coordinate, in tiles, not pixels.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
|
|
|
*
|
|
|
|
* @return {?Phaser.Math.Vector2[]} Returns an array of Vector2s, or null if the layer given was invalid.
|
|
|
|
*/
|
|
|
|
getTileCorners: function (tileX, tileY, camera, layer)
|
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
|
|
|
|
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
return this._convert.GetTileCorners(tileX, tileY, camera, layer);
|
|
|
|
},
|
|
|
|
|
2017-12-03 14:56:12 +00:00
|
|
|
/**
|
2018-02-07 23:12:55 +00:00
|
|
|
* Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the
|
|
|
|
* specified layer. Each tile will receive a new index. New indexes are drawn from the given
|
|
|
|
* weightedIndexes array. An example weighted array:
|
|
|
|
*
|
|
|
|
* [
|
|
|
|
* { index: 6, weight: 4 }, // Probability of index 6 is 4 / 8
|
|
|
|
* { index: 7, weight: 2 }, // Probability of index 7 would be 2 / 8
|
|
|
|
* { index: 8, weight: 1.5 }, // Probability of index 8 would be 1.5 / 8
|
|
|
|
* { index: 26, weight: 0.5 } // Probability of index 27 would be 0.5 / 8
|
|
|
|
* ]
|
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* The probability of any index being picked is (the indexs weight) / (sum of all weights). This
|
2018-02-07 23:12:55 +00:00
|
|
|
* method only modifies tile indexes and does not change collision information.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2017-12-03 14:56:12 +00:00
|
|
|
*
|
2018-02-07 23:12:55 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#weightedRandomize
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {object[]} weightedIndexes - An array of objects to randomly draw from during randomization. They should be in the form: { index: 0, weight: 4 } or { index: [0, 1], weight: 4 } if you wish to draw from multiple tile indexes.
|
|
|
|
* @param {number} [tileX] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [tileY] - The top most tile index (in tile coordinates) to use as the origin of the area.
|
|
|
|
* @param {number} [width] - How many tiles wide from the `tileX` index the area will be.
|
|
|
|
* @param {number} [height] - How many tiles tall from the `tileY` index the area will be.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:12:55 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?Phaser.Tilemaps.Tilemap} Return this Tilemap object, or null if the layer given was invalid.
|
2017-12-03 14:56:12 +00:00
|
|
|
*/
|
2020-11-26 12:55:40 +00:00
|
|
|
weightedRandomize: function (weightedIndexes, tileX, tileY, width, height, layer)
|
2017-12-03 14:56:12 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2019-04-08 14:59:48 +00:00
|
|
|
if (layer === null) { return null; }
|
|
|
|
|
|
|
|
TilemapComponents.WeightedRandomize(tileX, tileY, width, height, weightedIndexes, layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2017-12-03 14:56:12 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-30 15:22:54 +00:00
|
|
|
/**
|
2018-02-07 23:12:55 +00:00
|
|
|
* Converts from world X coordinates (pixels) to tile X coordinates (tile units), factoring in the
|
|
|
|
* layers position, scale and scroll.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2022-11-24 00:41:55 +00:00
|
|
|
* You cannot call this method for Isometric or Hexagonal tilemaps as they require
|
|
|
|
* both `worldX` and `worldY` values to determine the correct tile, instead you
|
|
|
|
* should use the `worldToTileXY` method.
|
|
|
|
*
|
2018-02-07 23:12:55 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#worldToTileX
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 15:22:54 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The x coordinate to be converted, in pixels, not tiles.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [snapToFloor] - Whether or not to round the tile coordinate down to the nearest integer.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:12:55 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?number} Returns a number, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-25 13:08:06 +00:00
|
|
|
worldToTileX: function (worldX, snapToFloor, camera, layer)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2017-11-17 02:36:45 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2020-10-02 10:53:23 +00:00
|
|
|
return this._convert.WorldToTileX(worldX, snapToFloor, camera, layer);
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:12:55 +00:00
|
|
|
* Converts from world Y coordinates (pixels) to tile Y coordinates (tile units), factoring in the
|
|
|
|
* layers position, scale and scroll.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2022-11-24 00:41:55 +00:00
|
|
|
* You cannot call this method for Isometric or Hexagonal tilemaps as they require
|
|
|
|
* both `worldX` and `worldY` values to determine the correct tile, instead you
|
|
|
|
* should use the `worldToTileXY` method.
|
|
|
|
*
|
2018-02-07 23:12:55 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#worldToTileY
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [snapToFloor] - Whether or not to round the tile coordinate down to the nearest integer.
|
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:12:55 +00:00
|
|
|
*
|
2018-03-20 11:36:35 +00:00
|
|
|
* @return {?number} Returns a number, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2017-11-25 13:08:06 +00:00
|
|
|
worldToTileY: function (worldY, snapToFloor, camera, layer)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2017-11-17 02:36:45 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2020-10-02 10:53:23 +00:00
|
|
|
return this._convert.WorldToTileY(worldY, snapToFloor, camera, layer);
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2018-02-07 23:12:55 +00:00
|
|
|
* Converts from world XY coordinates (pixels) to tile XY coordinates (tile units), factoring in the
|
|
|
|
* layers position, scale and scroll. This will return a new Vector2 object or update the given
|
|
|
|
* `point` object.
|
2018-03-20 11:36:35 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* If no layer is specified, the maps current layer is used.
|
2018-02-07 23:08:37 +00:00
|
|
|
*
|
2018-02-07 23:12:55 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#worldToTileXY
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2018-09-28 13:02:12 +00:00
|
|
|
* @param {number} worldX - The x coordinate to be converted, in pixels, not tiles.
|
|
|
|
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {boolean} [snapToFloor] - Whether or not to round the tile coordinate down to the nearest integer.
|
2020-10-12 10:40:40 +00:00
|
|
|
* @param {Phaser.Math.Vector2} [vec2] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
|
2020-11-26 12:55:40 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The Camera to use when calculating the tile index from the world values.
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number|Phaser.Tilemaps.TilemapLayer)} [layer] - The tile layer to use. If not given the current layer is used.
|
2018-02-07 23:12:55 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @return {?Phaser.Math.Vector2} Returns a vec2, or null if the layer given was invalid.
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2020-10-12 10:40:40 +00:00
|
|
|
worldToTileXY: function (worldX, worldY, snapToFloor, vec2, camera, layer)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
|
|
|
layer = this.getLayer(layer);
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2017-11-17 02:36:45 +00:00
|
|
|
if (layer === null) { return null; }
|
2018-02-07 23:12:55 +00:00
|
|
|
|
2020-10-12 10:40:40 +00:00
|
|
|
return this._convert.WorldToTileXY(worldX, worldY, snapToFloor, vec2, camera, layer);
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-30 00:54:29 +00:00
|
|
|
/**
|
2020-10-12 10:40:40 +00:00
|
|
|
* Removes all layer data from this Tilemap and nulls the scene reference. This will destroy any
|
|
|
|
* TilemapLayers that have been created.
|
2017-11-30 00:54:29 +00:00
|
|
|
*
|
2020-10-12 10:40:40 +00:00
|
|
|
* @method Phaser.Tilemaps.Tilemap#destroy
|
2018-02-07 23:08:37 +00:00
|
|
|
* @since 3.0.0
|
2017-11-30 00:54:29 +00:00
|
|
|
*/
|
2020-10-12 10:40:40 +00:00
|
|
|
destroy: function ()
|
2017-11-17 01:58:35 +00:00
|
|
|
{
|
2020-10-12 10:40:40 +00:00
|
|
|
this.removeAllLayers();
|
|
|
|
|
2023-03-26 21:31:52 +00:00
|
|
|
this.tiles.length = 0;
|
2020-10-12 10:40:40 +00:00
|
|
|
this.tilesets.length = 0;
|
|
|
|
this.objects.length = 0;
|
|
|
|
|
|
|
|
this.scene = null;
|
2017-11-11 16:38:52 +00:00
|
|
|
}
|
2017-11-15 20:55:26 +00:00
|
|
|
|
2017-11-11 16:38:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Tilemap;
|