mirror of
https://github.com/photonstorm/phaser
synced 2024-11-25 06:00:41 +00:00
Every single Tilemap.Component
function has now been made public. This means you can call the Component functions directly, should you need to, outside of the Tilemap system.
This commit is contained in:
parent
09f11b84e6
commit
0d934c730e
45 changed files with 113 additions and 83 deletions
|
@ -300,6 +300,7 @@ The way in which Game Objects add themselves to the Scene Update List has change
|
|||
* The `Phaser.Scenes.GetScenePlugins` function has now been exposed on the Phaser namespace (thanks @samme)
|
||||
* The `Phaser.Structs.Events` namespace has now been exposed on the Phaser namespace (thanks @samme)
|
||||
* The `Phaser.Tilemaps.Parsers.Tiled` function has now been exposed on the Phaser namespace (thanks @samme)
|
||||
* Every single `Tilemap.Component` function has now been made public. This means you can call the Component functions directly, should you need to, outside of the Tilemap system.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -12,9 +12,8 @@ var GetTileAt = require('./GetTileAt');
|
|||
* internally to optimize recalculating faces when only one tile has been changed.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.CalculateFacesAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
*
|
||||
* @param {integer} tileX - The x coordinate.
|
||||
* @param {integer} tileY - The y coordinate.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
|
@ -40,29 +39,48 @@ var CalculateFacesAt = function (tileX, tileY, layer)
|
|||
// Reset edges that are shared between tile and its neighbors
|
||||
if (above && above.collides)
|
||||
{
|
||||
if (tileCollides) { tile.faceTop = false; }
|
||||
if (tileCollides)
|
||||
{
|
||||
tile.faceTop = false;
|
||||
}
|
||||
|
||||
above.faceBottom = !tileCollides;
|
||||
}
|
||||
|
||||
if (below && below.collides)
|
||||
{
|
||||
if (tileCollides) { tile.faceBottom = false; }
|
||||
if (tileCollides)
|
||||
{
|
||||
tile.faceBottom = false;
|
||||
}
|
||||
|
||||
below.faceTop = !tileCollides;
|
||||
}
|
||||
|
||||
if (left && left.collides)
|
||||
{
|
||||
if (tileCollides) { tile.faceLeft = false; }
|
||||
if (tileCollides)
|
||||
{
|
||||
tile.faceLeft = false;
|
||||
}
|
||||
|
||||
left.faceRight = !tileCollides;
|
||||
}
|
||||
|
||||
if (right && right.collides)
|
||||
{
|
||||
if (tileCollides) { tile.faceRight = false; }
|
||||
if (tileCollides)
|
||||
{
|
||||
tile.faceRight = false;
|
||||
}
|
||||
|
||||
right.faceLeft = !tileCollides;
|
||||
}
|
||||
|
||||
if (tile && !tile.collides) { tile.resetFaces(); }
|
||||
if (tile && !tile.collides)
|
||||
{
|
||||
tile.resetFaces();
|
||||
}
|
||||
|
||||
return tile;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* is mostly used internally.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.CalculateFacesWithin
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
|
|
@ -13,7 +13,6 @@ var CalculateFacesWithin = require('./CalculateFacesWithin');
|
|||
* information in the destination region.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.Copy
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} srcTileX - The x coordinate of the area to copy from, in tiles, not pixels.
|
||||
|
@ -40,6 +39,7 @@ var Copy = function (srcTileX, srcTileY, width, height, destTileX, destTileY, re
|
|||
{
|
||||
var tileX = srcTiles[i].x + offsetX;
|
||||
var tileY = srcTiles[i].y + offsetY;
|
||||
|
||||
if (tileX >= 0 && tileX < layer.width && tileY >= 0 && tileY < layer.height)
|
||||
{
|
||||
if (layer.data[tileY][tileX])
|
||||
|
|
|
@ -16,11 +16,10 @@ var ReplaceByIndex = require('./ReplaceByIndex');
|
|||
* Sprites, but want to replace the tile itself with a floor tile or similar once converted.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.CreateFromTiles
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer|array)} indexes - The tile index, or array of indexes, to create Sprites from.
|
||||
* @param {(integer|array)} replacements - The tile index, or array of indexes, to change a converted 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.
|
||||
* @param {(number|number[])} indexes - The tile index, or array of indexes, to create Sprites from.
|
||||
* @param {(number|number[])} replacements - The tile index, or array of indexes, to change a converted 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.
|
||||
* @param {Phaser.Types.GameObjects.Sprite.SpriteConfig} spriteConfig - The config object to pass into the Sprite creator (i.e. scene.make.sprite).
|
||||
* @param {Phaser.Scene} [scene=scene the map is within] - The Scene to create the Sprites within.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when determining the world XY
|
||||
|
@ -32,9 +31,13 @@ var CreateFromTiles = function (indexes, replacements, spriteConfig, scene, came
|
|||
{
|
||||
if (spriteConfig === undefined) { spriteConfig = {}; }
|
||||
|
||||
if (!Array.isArray(indexes)) { indexes = [ indexes ]; }
|
||||
if (!Array.isArray(indexes))
|
||||
{
|
||||
indexes = [ indexes ];
|
||||
}
|
||||
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
|
||||
if (scene === undefined) { scene = tilemapLayer.scene; }
|
||||
if (camera === undefined) { camera = scene.cameras.main; }
|
||||
|
||||
|
@ -51,8 +54,7 @@ var CreateFromTiles = function (indexes, replacements, spriteConfig, scene, came
|
|||
spriteConfig.x = TileToWorldX(tile.x, camera, layer);
|
||||
spriteConfig.y = TileToWorldY(tile.y, camera, layer);
|
||||
|
||||
var sprite = scene.make.sprite(spriteConfig);
|
||||
sprites.push(sprite);
|
||||
sprites.push(scene.make.sprite(spriteConfig));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ var SnapCeil = require('../../math/snap/SnapCeil');
|
|||
* Returns the tiles in the given layer that are within the camera's viewport. This is used internally.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.CullTiles
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
|
|
|
@ -14,7 +14,6 @@ var SetTileCollision = require('./SetTileCollision');
|
|||
* Collision information in the region will be recalculated.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.Fill
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} index - The tile index to fill the area with.
|
||||
|
|
|
@ -12,7 +12,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.FilterTiles
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {function} callback - The callback. Each tile in the given area will be passed to this
|
||||
|
@ -28,7 +27,7 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* @param {boolean} [filteringOptions.isColliding=false] - If true, only return tiles that collide on at least one side.
|
||||
* @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that have at least one interesting face.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tile[]} The filtered array of Tiles.
|
||||
*/
|
||||
var FilterTiles = function (callback, context, tileX, tileY, width, height, filteringOptions, layer)
|
||||
|
@ -39,4 +38,3 @@ var FilterTiles = function (callback, context, tileX, tileY, width, height, filt
|
|||
};
|
||||
|
||||
module.exports = FilterTiles;
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
* the top-left.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.FindByIndex
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} index - The tile index value to search for.
|
||||
|
|
|
@ -22,7 +22,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* true. Similar to Array.prototype.find in vanilla JS.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.FindTile
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {FindTileCallback} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
|
||||
|
|
|
@ -19,7 +19,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* callback. Similar to Array.prototype.forEach in vanilla JS.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.ForEachTile
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {EachTileCallback} callback - The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
|
||||
|
|
|
@ -10,14 +10,13 @@ var IsInLayerBounds = require('./IsInLayerBounds');
|
|||
* Gets a tile at the given tile coordinates from the given layer.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.GetTileAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - X position to get the tile from (given in tile units, not pixels).
|
||||
* @param {integer} tileY - Y position to get the tile from (given in tile units, not pixels).
|
||||
* @param {boolean} [nonNull=false] - If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tile} The tile at the given coordinates or null if no tile was found or the coordinates
|
||||
* were invalid.
|
||||
*/
|
||||
|
|
|
@ -12,7 +12,6 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* Gets a tile at the given world coordinates from the given layer.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.GetTileAtWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - X position to get the tile from (given in pixels)
|
||||
|
@ -20,7 +19,7 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* @param {boolean} [nonNull=false] - 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=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tile} The tile at the given coordinates or null if no tile was found or the coordinates
|
||||
* were invalid.
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,6 @@ var GetFastValue = require('../../utils/object/GetFastValue');
|
|||
* Gets the tiles in the given rectangular area (in tile coordinates) of the layer.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.GetTilesWithin
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
@ -19,7 +18,7 @@ var GetFastValue = require('../../utils/object/GetFastValue');
|
|||
* @param {integer} height - How many tiles tall from the `tileY` index the area will be.
|
||||
* @param {Phaser.Types.Tilemaps.GetTilesWithinFilteringOptions} GetTilesWithinFilteringOptions - Optional filters to apply when getting the tiles.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tile[]} Array of Tile objects.
|
||||
*/
|
||||
var GetTilesWithin = function (tileX, tileY, width, height, filteringOptions, layer)
|
||||
|
@ -39,6 +38,7 @@ var GetTilesWithin = function (tileX, tileY, width, height, filteringOptions, la
|
|||
width += tileX;
|
||||
tileX = 0;
|
||||
}
|
||||
|
||||
if (tileY < 0)
|
||||
{
|
||||
height += tileY;
|
||||
|
@ -50,6 +50,7 @@ var GetTilesWithin = function (tileX, tileY, width, height, filteringOptions, la
|
|||
{
|
||||
width = Math.max(layer.width - tileX, 0);
|
||||
}
|
||||
|
||||
if (tileY + height > layer.height)
|
||||
{
|
||||
height = Math.max(layer.height - tileY, 0);
|
||||
|
@ -62,11 +63,24 @@ var GetTilesWithin = function (tileX, tileY, width, height, filteringOptions, la
|
|||
for (var tx = tileX; tx < tileX + width; tx++)
|
||||
{
|
||||
var tile = layer.data[ty][tx];
|
||||
|
||||
if (tile !== null)
|
||||
{
|
||||
if (isNotEmpty && tile.index === -1) { continue; }
|
||||
if (isColliding && !tile.collides) { continue; }
|
||||
if (hasInterestingFace && !tile.hasInterestingFace) { continue; }
|
||||
if (isNotEmpty && tile.index === -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isColliding && !tile.collides)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasInterestingFace && !tile.hasInterestingFace)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
results.push(tile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ var TriangleToRectangle = function (triangle, rect)
|
|||
* Line, Rectangle or Triangle. The shape should be in world coordinates.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.GetTilesWithinShape
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(Phaser.Geom.Circle|Phaser.Geom.Line|Phaser.Geom.Rectangle|Phaser.Geom.Triangle)} shape - A shape in world (pixel) coordinates
|
||||
|
@ -45,10 +44,33 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
|||
|
||||
// intersectTest is a function with parameters: shape, rect
|
||||
var intersectTest = NOOP;
|
||||
if (shape instanceof Geom.Circle) { intersectTest = Intersects.CircleToRectangle; }
|
||||
else if (shape instanceof Geom.Rectangle) { intersectTest = Intersects.RectangleToRectangle; }
|
||||
else if (shape instanceof Geom.Triangle) { intersectTest = TriangleToRectangle; }
|
||||
else if (shape instanceof Geom.Line) { intersectTest = Intersects.LineToRectangle; }
|
||||
|
||||
switch (typeof(shape))
|
||||
{
|
||||
case Geom.Circle:
|
||||
{
|
||||
intersectTest = Intersects.CircleToRectangle;
|
||||
break;
|
||||
}
|
||||
|
||||
case Geom.Rectangle:
|
||||
{
|
||||
intersectTest = Intersects.RectangleToRectangle;
|
||||
break;
|
||||
}
|
||||
|
||||
case Geom.Triangle:
|
||||
{
|
||||
intersectTest = TriangleToRectangle;
|
||||
break;
|
||||
}
|
||||
|
||||
case Geom.Line:
|
||||
{
|
||||
intersectTest = Intersects.LineToRectangle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Top left corner of the shapes's bounding box, rounded down to include partial tiles
|
||||
var xStart = WorldToTileX(shape.left, true, camera, layer);
|
||||
|
@ -66,6 +88,7 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
|||
|
||||
var tileWidth = layer.tileWidth;
|
||||
var tileHeight = layer.tileHeight;
|
||||
|
||||
if (layer.tilemapLayer)
|
||||
{
|
||||
tileWidth *= layer.tilemapLayer.scaleX;
|
||||
|
@ -74,11 +97,14 @@ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer)
|
|||
|
||||
var results = [];
|
||||
var tileRect = new Geom.Rectangle(0, 0, tileWidth, tileHeight);
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
var tile = tiles[i];
|
||||
|
||||
tileRect.x = TileToWorldX(tile.x, camera, layer);
|
||||
tileRect.y = TileToWorldY(tile.y, camera, layer);
|
||||
|
||||
if (intersectTest(shape, tileRect))
|
||||
{
|
||||
results.push(tile);
|
||||
|
|
|
@ -12,7 +12,6 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* Gets the tiles in the given rectangular area (in world coordinates) of the layer.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.GetTilesWithinWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - The world x coordinate for the top-left of the area.
|
||||
|
@ -25,7 +24,7 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that have at least one interesting face.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when factoring in which tiles to return.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tile[]} Array of Tile objects.
|
||||
*/
|
||||
var GetTilesWithinWorldXY = function (worldX, worldY, width, height, filteringOptions, camera, layer)
|
||||
|
|
|
@ -11,13 +11,12 @@ var IsInLayerBounds = require('./IsInLayerBounds');
|
|||
* false if there is no tile or if the tile at that location has an index of -1.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.HasTileAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - X position to get the tile from (given in tile units, not pixels).
|
||||
* @param {integer} tileY - Y position to get the tile from (given in tile units, not pixels).
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {?boolean} Returns a boolean, or null if the layer given was invalid.
|
||||
*/
|
||||
var HasTileAt = function (tileX, tileY, layer)
|
||||
|
@ -25,13 +24,13 @@ var HasTileAt = function (tileX, tileY, layer)
|
|||
if (IsInLayerBounds(tileX, tileY, layer))
|
||||
{
|
||||
var tile = layer.data[tileY][tileX];
|
||||
|
||||
return (tile !== null && tile.index > -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = HasTileAt;
|
||||
|
|
|
@ -13,14 +13,13 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* false if there is no tile or if the tile at that location has an index of -1.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.HasTileAtWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - The X coordinate of the world position.
|
||||
* @param {number} worldY - The Y coordinate of the world position.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when factoring in which tiles to return.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {?boolean} Returns a boolean, or null if the layer given was invalid.
|
||||
*/
|
||||
var HasTileAtWorldXY = function (worldX, worldY, camera, layer)
|
||||
|
|
|
@ -8,13 +8,12 @@
|
|||
* Checks if the given tile coordinates are within the bounds of the layer.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.IsInLayerBounds
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
|
||||
* @param {integer} tileY - The y coordinate, in tiles, not pixels.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {boolean} `true` if the tile coordinates are within the bounds of the layer, otherwise `false`.
|
||||
*/
|
||||
var IsInLayerBounds = function (tileX, tileY, layer)
|
||||
|
|
|
@ -16,7 +16,6 @@ var SetTileCollision = require('./SetTileCollision');
|
|||
* Collision information will be recalculated at the specified location.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.PutTileAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer|Phaser.Tilemaps.Tile)} tile - The index of this tile to set or a Tile object.
|
||||
|
@ -41,11 +40,13 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
|
|||
{
|
||||
layer.data[tileY][tileX] = new Tile(layer, tile.index, tileX, tileY, tile.width, tile.height);
|
||||
}
|
||||
|
||||
layer.data[tileY][tileX].copy(tile);
|
||||
}
|
||||
else
|
||||
{
|
||||
var index = tile;
|
||||
|
||||
if (layer.data[tileY][tileX] === null)
|
||||
{
|
||||
layer.data[tileY][tileX] = new Tile(layer, index, tileX, tileY, layer.tileWidth, layer.tileHeight);
|
||||
|
@ -59,6 +60,7 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
|
|||
// Updating colliding flag on the new tile
|
||||
var newTile = layer.data[tileY][tileX];
|
||||
var collides = layer.collideIndexes.indexOf(newTile.index) !== -1;
|
||||
|
||||
SetTileCollision(newTile, collides);
|
||||
|
||||
// Recalculate faces only if the colliding flag at (tileX, tileY) has changed
|
||||
|
@ -71,4 +73,3 @@ var PutTileAt = function (tile, tileX, tileY, recalculateFaces, layer)
|
|||
};
|
||||
|
||||
module.exports = PutTileAt;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* changed. Collision information will be recalculated at the specified location.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.PutTileAtWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer|Phaser.Tilemaps.Tile)} tile - The index of this tile to set or a Tile object.
|
||||
|
@ -31,6 +30,7 @@ var PutTileAtWorldXY = function (tile, worldX, worldY, recalculateFaces, camera,
|
|||
{
|
||||
var tileX = WorldToTileX(worldX, true, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, true, camera, layer);
|
||||
|
||||
return PutTileAt(tile, tileX, tileY, recalculateFaces, layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ var PutTileAt = require('./PutTileAt');
|
|||
* within the region tiles were changed.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.PutTilesAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer[]|integer[][]|Phaser.Tilemaps.Tile[]|Phaser.Tilemaps.Tile[][])} tile - A row (array) or grid (2D array) of Tiles or tile indexes to place.
|
||||
|
@ -43,6 +42,7 @@ var PutTilesAt = function (tilesArray, tileX, tileY, recalculateFaces, layer)
|
|||
for (var tx = 0; tx < width; tx++)
|
||||
{
|
||||
var tile = tilesArray[ty][tx];
|
||||
|
||||
PutTileAt(tile, tileX + tx, tileY + ty, false, layer);
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,3 @@ var PutTilesAt = function (tilesArray, tileX, tileY, recalculateFaces, layer)
|
|||
};
|
||||
|
||||
module.exports = PutTilesAt;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ var GetRandom = require('../../utils/array/GetRandom');
|
|||
* indexes. This method only modifies tile indexes and does not change collision information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.Randomize
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
@ -34,6 +33,7 @@ var Randomize = function (tileX, tileY, width, height, indexes, layer)
|
|||
if (indexes === undefined)
|
||||
{
|
||||
indexes = [];
|
||||
|
||||
for (i = 0; i < tiles.length; i++)
|
||||
{
|
||||
if (indexes.indexOf(tiles[i].index) === -1)
|
||||
|
|
|
@ -13,7 +13,6 @@ var CalculateFacesAt = require('./CalculateFacesAt');
|
|||
* collision information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.RemoveTileAt
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The x coordinate.
|
||||
|
|
|
@ -13,7 +13,6 @@ var WorldToTileY = require('./WorldToTileY');
|
|||
* collision information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.RemoveTileAtWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - The x coordinate, in pixels.
|
||||
|
@ -29,6 +28,7 @@ var RemoveTileAtWorldXY = function (worldX, worldY, replaceWithNull, recalculate
|
|||
{
|
||||
var tileX = WorldToTileX(worldX, true, camera, layer);
|
||||
var tileY = WorldToTileY(worldY, true, camera, layer);
|
||||
|
||||
return RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, layer);
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ var defaultFaceColor = new Color(40, 39, 37, 150);
|
|||
* wherever you want on the screen.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.RenderDebug
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Graphics} graphics - The target Graphics object to draw upon.
|
||||
|
|
|
@ -12,7 +12,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* not change collision information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.ReplaceByIndex
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} findIndex - The index of the tile to search for.
|
||||
|
|
|
@ -14,7 +14,6 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex');
|
|||
* collision will be enabled (true) or disabled (false).
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetCollision
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer|array)} indexes - Either a single tile index, or an array of tile indexes.
|
||||
|
@ -36,7 +35,7 @@ var SetCollision = function (indexes, collides, recalculateFaces, layer, updateL
|
|||
{
|
||||
SetLayerCollisionIndex(indexes[i], collides, layer);
|
||||
}
|
||||
|
||||
|
||||
// Update the tiles
|
||||
if (updateLayer)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,6 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex');
|
|||
* enabled (true) or disabled (false).
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetCollisionBetween
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} start - The first index of the tile to be set for collision.
|
||||
|
@ -48,7 +47,7 @@ var SetCollisionBetween = function (start, stop, collides, recalculateFaces, lay
|
|||
for (var tx = 0; tx < layer.width; tx++)
|
||||
{
|
||||
var tile = layer.data[ty][tx];
|
||||
|
||||
|
||||
if (tile)
|
||||
{
|
||||
if (tile.index >= start && tile.index <= stop)
|
||||
|
|
|
@ -14,7 +14,6 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex');
|
|||
* disabled (false). Tile indexes not currently in the layer are not affected.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetCollisionByExclusion
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer[]} indexes - An array of the tile indexes to not be counted for collision.
|
||||
|
|
|
@ -18,7 +18,6 @@ var HasValue = require('../../utils/object/HasValue');
|
|||
* "types" property that matches any of those values, its collision flag will be updated.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetCollisionByProperty
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} properties - An object with tile properties and corresponding values that should be checked.
|
||||
|
|
|
@ -14,7 +14,6 @@ var CalculateFacesWithin = require('./CalculateFacesWithin');
|
|||
* controls if collision will be enabled (true) or disabled (false).
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetCollisionFromCollisionGroup
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {boolean} [collides=true] - If true it will enable collision. If false it will clear collision.
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* updates LayerData.collideIndexes to either contain or not contain the given `tileIndex`.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetLayerCollisionIndex
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileIndex - The tile index to set the collision boolean for.
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
* interesting faces.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetTileCollision
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Tilemaps.Tile} tile - The Tile to set the collision on.
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
* at a specific location on the map then see setTileLocationCallback.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetTileIndexCallback
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(integer|array)} indexes - Either a single tile index, or an array of tile indexes to have a collision callback set for.
|
||||
|
|
|
@ -12,7 +12,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* remove it.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SetTileLocationCallback
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
@ -31,7 +30,6 @@ var SetTileLocationCallback = function (tileX, tileY, width, height, callback, c
|
|||
{
|
||||
tiles[i].setCollisionCallback(callback, callbackContext);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = SetTileLocationCallback;
|
||||
|
|
|
@ -14,7 +14,6 @@ var ShuffleArray = require('../../utils/array/Shuffle');
|
|||
* information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.Shuffle
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
@ -28,6 +27,7 @@ var Shuffle = function (tileX, tileY, width, height, layer)
|
|||
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
||||
|
||||
var indexes = tiles.map(function (tile) { return tile.index; });
|
||||
|
||||
ShuffleArray(indexes);
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
|
|
|
@ -12,7 +12,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.SwapByIndex
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileA - First tile index.
|
||||
|
@ -26,6 +25,7 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
var SwapByIndex = function (indexA, indexB, tileX, tileY, width, height, layer)
|
||||
{
|
||||
var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer);
|
||||
|
||||
for (var i = 0; i < tiles.length; i++)
|
||||
{
|
||||
if (tiles[i])
|
||||
|
|
|
@ -9,13 +9,12 @@
|
|||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.TileToWorldX
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
var TileToWorldX = function (tileX, camera, layer)
|
||||
|
|
|
@ -14,7 +14,6 @@ var Vector2 = require('../../math/Vector2');
|
|||
* `point` object.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.TileToWorldXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileX - The x coordinate, in tiles, not pixels.
|
||||
|
@ -22,7 +21,7 @@ var Vector2 = require('../../math/Vector2');
|
|||
* @param {Phaser.Math.Vector2} [point] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Math.Vector2} The XY location in world coordinates.
|
||||
*/
|
||||
var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
||||
|
|
|
@ -9,13 +9,12 @@
|
|||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.TileToWorldY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} tileY - The x coordinate, in tiles, not pixels.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
var TileToWorldY = function (tileY, camera, layer)
|
||||
|
|
|
@ -22,7 +22,6 @@ var GetTilesWithin = require('./GetTilesWithin');
|
|||
* method only modifies tile indexes and does not change collision information.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.WeightedRandomize
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} [tileX=0] - The left most tile index (in tile coordinates) to use as the origin of the area.
|
||||
|
@ -54,12 +53,15 @@ var WeightedRandomize = function (tileX, tileY, width, height, weightedIndexes,
|
|||
var rand = Math.random() * weightTotal;
|
||||
var sum = 0;
|
||||
var randomIndex = -1;
|
||||
|
||||
for (var j = 0; j < weightedIndexes.length; j++)
|
||||
{
|
||||
sum += weightedIndexes[j].weight;
|
||||
|
||||
if (rand <= sum)
|
||||
{
|
||||
var chosen = weightedIndexes[j].index;
|
||||
|
||||
randomIndex = Array.isArray(chosen)
|
||||
? chosen[Math.floor(Math.random() * chosen.length)]
|
||||
: chosen;
|
||||
|
|
|
@ -9,14 +9,13 @@
|
|||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.WorldToTileX
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - The x coordinate to be converted, in pixels, not tiles.
|
||||
* @param {boolean} [snapToFloor=true] - Whether or not to round the tile coordinate down to the nearest integer.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {number} The X location in tile units.
|
||||
*/
|
||||
var WorldToTileX = function (worldX, snapToFloor, camera, layer)
|
||||
|
|
|
@ -14,7 +14,6 @@ var Vector2 = require('../../math/Vector2');
|
|||
* `point` object.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.WorldToTileXY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldX - The x coordinate to be converted, in pixels, not tiles.
|
||||
|
@ -23,7 +22,7 @@ var Vector2 = require('../../math/Vector2');
|
|||
* @param {Phaser.Math.Vector2} [point] - A Vector2 to store the coordinates in. If not given a new Vector2 is created.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {Phaser.Math.Vector2} The XY location in tile units.
|
||||
*/
|
||||
var WorldToTileXY = function (worldX, worldY, snapToFloor, point, camera, layer)
|
||||
|
|
|
@ -9,14 +9,13 @@
|
|||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @function Phaser.Tilemaps.Components.WorldToTileY
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} worldY - The y coordinate to be converted, in pixels, not tiles.
|
||||
* @param {boolean} [snapToFloor=true] - Whether or not to round the tile coordinate down to the nearest integer.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera=main camera] - The Camera to use when calculating the tile index from the world values.
|
||||
* @param {Phaser.Tilemaps.LayerData} layer - The Tilemap Layer to act upon.
|
||||
*
|
||||
*
|
||||
* @return {number} The Y location in tile units.
|
||||
*/
|
||||
var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
||||
|
|
Loading…
Reference in a new issue