2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-01-11 02:47:25 +00:00
|
|
|
var ProcessTileSeparationX = require('./ProcessTileSeparationX');
|
|
|
|
|
|
|
|
/**
|
2018-02-09 03:44:23 +00:00
|
|
|
* Check the body against the given tile on the X axis.
|
2018-10-19 16:45:05 +00:00
|
|
|
* Used internally by the SeparateTile function.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Physics.Arcade.Tilemap.TileCheckX
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Arcade.Body} body - The Body object to separate.
|
|
|
|
* @param {Phaser.Tilemaps.Tile} tile - The tile to check.
|
2018-10-19 16:45:05 +00:00
|
|
|
* @param {number} tileLeft - The left position of the tile within the tile world.
|
|
|
|
* @param {number} tileRight - The right position of the tile within the tile world.
|
|
|
|
* @param {number} tileBias - The tile bias value. Populated by the `World.TILE_BIAS` constant.
|
2018-02-09 03:44:23 +00:00
|
|
|
*
|
|
|
|
* @return {number} The amount of separation that occurred.
|
|
|
|
*/
|
2018-01-17 01:03:13 +00:00
|
|
|
var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
var ox = 0;
|
|
|
|
|
|
|
|
if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left)
|
|
|
|
{
|
|
|
|
// Body is moving LEFT
|
|
|
|
if (tile.faceRight && body.x < tileRight)
|
|
|
|
{
|
|
|
|
ox = body.x - tileRight;
|
|
|
|
|
2018-01-11 14:32:07 +00:00
|
|
|
if (ox < -tileBias)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
ox = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (body.deltaX() > 0 && !body.blocked.right && tile.collideLeft && body.checkCollision.right)
|
|
|
|
{
|
|
|
|
// Body is moving RIGHT
|
|
|
|
if (tile.faceLeft && body.right > tileLeft)
|
|
|
|
{
|
|
|
|
ox = body.right - tileLeft;
|
|
|
|
|
2018-01-11 14:32:07 +00:00
|
|
|
if (ox > tileBias)
|
2018-01-11 02:47:25 +00:00
|
|
|
{
|
|
|
|
ox = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ox !== 0)
|
|
|
|
{
|
|
|
|
if (body.customSeparateX)
|
|
|
|
{
|
|
|
|
body.overlapX = ox;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ProcessTileSeparationX(body, ox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ox;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TileCheckX;
|