mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
5e89c9b1c7
9 changed files with 138 additions and 12 deletions
|
@ -1157,7 +1157,43 @@ var Tilemap = new Class({
|
|||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {number|null} Returns this, or null if the layer given was invalid.
|
||||
* @return {number|null} Returns a number, or null if the layer given was invalid.
|
||||
*/
|
||||
tileToWorldX: function (tileX, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.TileToWorldX(tileX, camera, layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {number|null} Returns a number, or null if the layer given was invalid.
|
||||
*/
|
||||
tileToWorldY: function (tileX, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.TileToWorldY(tileX, camera, layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {Vector2|null} Returns a point, or null if the layer given was invalid.
|
||||
*/
|
||||
tileToWorldXY: function (tileX, tileY, point, camera, layer)
|
||||
{
|
||||
layer = this.getLayer(layer);
|
||||
if (layer === null) { return null; }
|
||||
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {number|null} Returns a number, or null if the layer given was invalid.
|
||||
*/
|
||||
worldToTileX: function (worldX, snapToFloor, camera, layer)
|
||||
{
|
||||
|
@ -1169,7 +1205,7 @@ var Tilemap = new Class({
|
|||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {number|null} Returns this, or null if the layer given was invalid.
|
||||
* @return {number|null} Returns a number, or null if the layer given was invalid.
|
||||
*/
|
||||
worldToTileY: function (worldY, snapToFloor, camera, layer)
|
||||
{
|
||||
|
@ -1181,7 +1217,7 @@ var Tilemap = new Class({
|
|||
/**
|
||||
* See component documentation. If no layer specified, the map's current layer is used.
|
||||
*
|
||||
* @return {Vector|null} Returns this, or null if the layer given was invalid.
|
||||
* @return {Vector2|null} Returns a point, or null if the layer given was invalid.
|
||||
*/
|
||||
worldToTileXY: function (worldX, worldY, snapToFloor, point, camera, layer)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* Internally used method to convert from tile X coordinates to world X coordinates, factoring in
|
||||
* layer position, scale and scroll.
|
||||
* Converts from tile X coordinates (tile units) to world X coordinates (pixels), factoring in the
|
||||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @param {integer} tileX - [description]
|
||||
* @param {Camera} [camera=main camera] - [description]
|
||||
|
@ -17,7 +17,7 @@ var TileToWorldX = function (tileX, camera, layer)
|
|||
{
|
||||
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
||||
|
||||
layerWorldX = tilemapLayer.x - (camera.scrollX * tilemapLayer.scrollFactorX);
|
||||
layerWorldX = tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX);
|
||||
|
||||
tileWidth *= tilemapLayer.scaleX;
|
||||
}
|
||||
|
|
27
v3/src/gameobjects/tilemap/components/TileToWorldXY.js
Normal file
27
v3/src/gameobjects/tilemap/components/TileToWorldXY.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
var TileToWorldX = require('./TileToWorldX');
|
||||
var TileToWorldY = require('./TileToWorldY');
|
||||
var Vector2 = require('../../../math/Vector2');
|
||||
|
||||
/**
|
||||
* Converts from tile XY coordinates (tile units) to world XY coordinates (pixels), factoring in the
|
||||
* layer's position, scale and scroll. This will return a new Vector2 object or update the given
|
||||
* `point` object.
|
||||
*
|
||||
* @param {integer} tileX - [description]
|
||||
* @param {integer} tileY - [description]
|
||||
* @param {Vector2} [point] - [description]
|
||||
* @param {Camera} [camera=main camera] - [description]
|
||||
* @param {LayerData} layer - [description]
|
||||
* @returns {Vector2} The XY location in world coordinates.
|
||||
*/
|
||||
var TileToWorldXY = function (tileX, tileY, point, camera, layer)
|
||||
{
|
||||
if (point === undefined) { point = new Vector2(0, 0); }
|
||||
|
||||
point.x = TileToWorldX(tileX, camera, layer);
|
||||
point.y = TileToWorldY(tileY, camera, layer);
|
||||
|
||||
return point;
|
||||
};
|
||||
|
||||
module.exports = TileToWorldXY;
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* Internally used method to convert from tile Y coordinates to world Y coordinates, factoring in
|
||||
* layer position, scale and scroll.
|
||||
* Converts from tile Y coordinates (tile units) to world Y coordinates (pixels), factoring in the
|
||||
* layer's position, scale and scroll.
|
||||
*
|
||||
* @param {integer} tileY - [description]
|
||||
* @param {Camera} [camera=main camera] - [description]
|
||||
|
@ -17,7 +17,7 @@ var TileToWorldY = function (tileY, camera, layer)
|
|||
{
|
||||
if (camera === undefined) { camera = tilemapLayer.scene.cameras.main; }
|
||||
|
||||
layerWorldY = tilemapLayer.y - (camera.scrollY * tilemapLayer.scrollFactorY);
|
||||
layerWorldY = (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
||||
|
||||
tileHeight *= tilemapLayer.scaleY;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ var WorldToTileX = function (worldX, snapToFloor, camera, layer)
|
|||
|
||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||
// factoring in the camera's horizontal scroll
|
||||
worldX = worldX + (camera.scrollX * tilemapLayer.scrollFactorX) - tilemapLayer.x;
|
||||
worldX = worldX - (tilemapLayer.x + camera.scrollX * (1 - tilemapLayer.scrollFactorX));
|
||||
|
||||
tileWidth *= tilemapLayer.scaleX;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ var WorldToTileY = function (worldY, snapToFloor, camera, layer)
|
|||
|
||||
// Find the world position relative to the static or dynamic layer's top left origin,
|
||||
// factoring in the camera's vertical scroll
|
||||
worldY = worldY + (camera.scrollY * tilemapLayer.scrollFactorY) - tilemapLayer.y;
|
||||
worldY = worldY - (tilemapLayer.y + camera.scrollY * (1 - tilemapLayer.scrollFactorY));
|
||||
|
||||
tileHeight *= tilemapLayer.scaleY;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ module.exports = {
|
|||
SetTileLocationCallback: require('./SetTileLocationCallback'),
|
||||
Shuffle: require('./Shuffle'),
|
||||
SwapByIndex: require('./SwapByIndex'),
|
||||
TileToWorldX: require('./TileToWorldX'),
|
||||
TileToWorldXY: require('./TileToWorldXY'),
|
||||
TileToWorldY: require('./TileToWorldY'),
|
||||
WorldToTileX: require('./WorldToTileX'),
|
||||
WorldToTileXY: require('./WorldToTileXY'),
|
||||
WorldToTileY: require('./WorldToTileY')
|
||||
|
|
|
@ -425,6 +425,36 @@ var DynamicTilemapLayer = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
tileToWorldX: function (tileX, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldX(tileX, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
tileToWorldY: function (tileY, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldY(tileY, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {Vector2}
|
||||
*/
|
||||
tileToWorldXY: function (tileX, tileY, point, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
|
|
|
@ -469,6 +469,36 @@ var StaticTilemapLayer = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
tileToWorldX: function (tileX, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldX(tileX, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
tileToWorldY: function (tileY, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldY(tileY, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {Vector2}
|
||||
*/
|
||||
tileToWorldXY: function (tileX, tileY, point, camera)
|
||||
{
|
||||
return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer);
|
||||
},
|
||||
|
||||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
|
@ -492,7 +522,7 @@ var StaticTilemapLayer = new Class({
|
|||
/**
|
||||
* See component documentation.
|
||||
*
|
||||
* @return {Vector}
|
||||
* @return {Vector2}
|
||||
*/
|
||||
worldToTileXY: function (worldX, worldY, snapToFloor, point, camera)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue