Skip to content

Commit 8167d6d

Browse files
committed
New isLayer handling
1 parent d160df3 commit 8167d6d

3 files changed

Lines changed: 50 additions & 15 deletions

File tree

src/physics/arcade/tilemap/SeparateTile.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ var TileIntersectsBody = require('./TileIntersectsBody');
2020
* @param {Phaser.Geom.Rectangle} tileWorldRect - A rectangle-like object defining the dimensions of the tile.
2121
* @param {(Phaser.Tilemaps.DynamicTilemapLayer|Phaser.Tilemaps.StaticTilemapLayer)} tilemapLayer - The tilemapLayer to collide against.
2222
* @param {number} tileBias - The tile bias value. Populated by the `World.TILE_BIAS` constant.
23+
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
2324
*
2425
* @return {boolean} `true` if the body was separated, otherwise `false`.
2526
*/
26-
var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBias)
27+
var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBias, isLayer)
2728
{
2829
var tileLeft = tileWorldRect.left;
2930
var tileTop = tileWorldRect.top;
@@ -32,6 +33,12 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
3233
var faceHorizontal = tile.faceLeft || tile.faceRight;
3334
var faceVertical = tile.faceTop || tile.faceBottom;
3435

36+
if (!isLayer)
37+
{
38+
faceHorizontal = true;
39+
faceVertical = true;
40+
}
41+
3542
// We don't need to go any further if this tile doesn't actually have any colliding faces. This
3643
// could happen if the tile was meant to be collided with re: a callback, but otherwise isn't
3744
// needed for separation.
@@ -68,7 +75,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
6875
{
6976
if (faceHorizontal)
7077
{
71-
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
78+
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias, isLayer);
7279

7380
// That's horizontal done, check if we still intersects? If not then we can return now
7481
if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body))
@@ -79,14 +86,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
7986

8087
if (faceVertical)
8188
{
82-
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
89+
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias, isLayer);
8390
}
8491
}
8592
else
8693
{
8794
if (faceVertical)
8895
{
89-
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
96+
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias, isLayer);
9097

9198
// That's vertical done, check if we still intersects? If not then we can return now
9299
if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body))
@@ -97,7 +104,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
97104

98105
if (faceHorizontal)
99106
{
100-
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
107+
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias, isLayer);
101108
}
102109
}
103110

src/physics/arcade/tilemap/TileCheckX.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,31 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX');
1818
* @param {number} tileLeft - The left position of the tile within the tile world.
1919
* @param {number} tileRight - The right position of the tile within the tile world.
2020
* @param {number} tileBias - The tile bias value. Populated by the `World.TILE_BIAS` constant.
21+
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
2122
*
2223
* @return {number} The amount of separation that occurred.
2324
*/
24-
var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias)
25+
var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias, isLayer)
2526
{
2627
var ox = 0;
2728

28-
if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left)
29+
var faceLeft = tile.faceLeft;
30+
var faceRight = tile.faceRight;
31+
var collideLeft = tile.collideLeft;
32+
var collideRight = tile.collideRight;
33+
34+
if (!isLayer)
35+
{
36+
faceLeft = true;
37+
faceRight = true;
38+
collideLeft = true;
39+
collideRight = true;
40+
}
41+
42+
if (body.deltaX() < 0 && !body.blocked.left && collideRight && body.checkCollision.left)
2943
{
3044
// Body is moving LEFT
31-
if (tile.faceRight && body.x < tileRight)
45+
if (faceRight && body.x < tileRight)
3246
{
3347
ox = body.x - tileRight;
3448

@@ -38,10 +52,10 @@ var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias)
3852
}
3953
}
4054
}
41-
else if (body.deltaX() > 0 && !body.blocked.right && tile.collideLeft && body.checkCollision.right)
55+
else if (body.deltaX() > 0 && !body.blocked.right && collideLeft && body.checkCollision.right)
4256
{
4357
// Body is moving RIGHT
44-
if (tile.faceLeft && body.right > tileLeft)
58+
if (faceLeft && body.right > tileLeft)
4559
{
4660
ox = body.right - tileLeft;
4761

src/physics/arcade/tilemap/TileCheckY.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,31 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY');
1818
* @param {number} tileTop - The top position of the tile within the tile world.
1919
* @param {number} tileBottom - The bottom position of the tile within the tile world.
2020
* @param {number} tileBias - The tile bias value. Populated by the `World.TILE_BIAS` constant.
21+
* @param {boolean} isLayer - Is this check coming from a TilemapLayer or an array of tiles?
2122
*
2223
* @return {number} The amount of separation that occurred.
2324
*/
24-
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias)
25+
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias, isLayer)
2526
{
2627
var oy = 0;
2728

28-
if (body.deltaY() < 0 && !body.blocked.up && tile.collideDown && body.checkCollision.up)
29+
var faceTop = tile.faceTop;
30+
var faceBottom = tile.faceBottom;
31+
var collideUp = tile.collideUp;
32+
var collideDown = tile.collideDown;
33+
34+
if (!isLayer)
35+
{
36+
faceTop = true;
37+
faceBottom = true;
38+
collideUp = true;
39+
collideDown = true;
40+
}
41+
42+
if (body.deltaY() < 0 && !body.blocked.up && collideDown && body.checkCollision.up)
2943
{
3044
// Body is moving UP
31-
if (tile.faceBottom && body.y < tileBottom)
45+
if (faceBottom && body.y < tileBottom)
3246
{
3347
oy = body.y - tileBottom;
3448

@@ -38,10 +52,10 @@ var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias)
3852
}
3953
}
4054
}
41-
else if (body.deltaY() > 0 && !body.blocked.down && tile.collideUp && body.checkCollision.down)
55+
else if (body.deltaY() > 0 && !body.blocked.down && collideUp && body.checkCollision.down)
4256
{
4357
// Body is moving DOWN
44-
if (tile.faceTop && body.bottom > tileTop)
58+
if (faceTop && body.bottom > tileTop)
4559
{
4660
oy = body.bottom - tileTop;
4761

0 commit comments

Comments
 (0)