phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
87 lines (76 loc) • 2.51 kB
JavaScript
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2026 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var ProcessTileSeparationY = require('./ProcessTileSeparationY');
/**
* Checks for overlap between a physics body and a tile along the Y axis and resolves any
* collision that is found. If the body has a custom separator set, the overlap value is stored
* on `body.overlapY` for the caller to handle; otherwise `ProcessTileSeparationY` is called to
* resolve the collision immediately. Used internally by the SeparateTile function.
*
* @function Phaser.Physics.Arcade.Tilemap.TileCheckY
* @since 3.0.0
*
* @param {Phaser.Physics.Arcade.Body} body - The Body object to separate.
* @param {Phaser.Tilemaps.Tile} tile - The tile to check.
* @param {number} tileTop - The top position of the tile in world space, in pixels.
* @param {number} tileBottom - The bottom position of the tile in world space, in pixels.
* @param {number} tileBias - The tile bias value, as defined by the `World.TILE_BIAS` constant.
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
*
* @return {number} The amount of vertical separation that occurred, in pixels.
*/
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
{
var oy = 0;
var faceTop = tile.faceTop;
var faceBottom = tile.faceBottom;
var collideUp = tile.collideUp;
var collideDown = tile.collideDown;
if (!isLayer)
{
faceTop = true;
faceBottom = true;
collideUp = true;
collideDown = true;
}
if (body.deltaY() < 0 && collideDown && body.checkCollision.up)
{
// Body is moving UP
if (faceBottom && body.y < tileBottom)
{
oy = body.y - tileBottom;
if (oy < -tileBias)
{
oy = 0;
}
}
}
else if (body.deltaY() > 0 && collideUp && body.checkCollision.down)
{
// Body is moving DOWN
if (faceTop && body.bottom > tileTop)
{
oy = body.bottom - tileTop;
if (oy > tileBias)
{
oy = 0;
}
}
}
if (oy !== 0)
{
if (body.customSeparateY)
{
body.overlapY = oy;
}
else
{
ProcessTileSeparationY(body, oy);
}
}
return oy;
};
module.exports = TileCheckY;