Skip to content

Commit ca3c71e

Browse files
committed
Added max overlap clamp.
1 parent 8e289e6 commit ca3c71e

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

examples/wip/tilemap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function preload() {
88
// game.load.image('phaser', 'assets/sprites/phaser-ship.png');
99
// game.load.image('phaser', 'assets/sprites/mushroom2.png');
1010
// game.load.image('phaser', 'assets/sprites/wabbit.png');
11-
game.load.image('phaser', 'assets/sprites/arrow.png');
11+
// game.load.image('phaser', 'assets/sprites/arrow.png');
12+
game.load.image('phaser', 'assets/sprites/darkwing_crazy.png');
1213

1314
}
1415

src/physics/arcade/ArcadePhysics.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ Phaser.Physics.Arcade.prototype = {
10181018
var tile;
10191019
var localOverlapX = 0;
10201020
var localOverlapY = 0;
1021+
var maxOverlapX = Math.round(tiles[0].width / 2);
1022+
var maxOverlapY = Math.round(tiles[0].height / 2);
10211023

10221024
for (var i = 0; i < tiles.length; i++)
10231025
{
@@ -1030,6 +1032,11 @@ Phaser.Physics.Arcade.prototype = {
10301032
// LEFT
10311033
localOverlapX = body.x - tile.right;
10321034

1035+
if (localOverlapX < -maxOverlapX)
1036+
{
1037+
localOverlapX = 0;
1038+
}
1039+
10331040
if (localOverlapX >= body.deltaX())
10341041
{
10351042
console.log('m left overlapX', localOverlapX, body.deltaX(), this.game.time.physicsElapsed);
@@ -1044,6 +1051,11 @@ Phaser.Physics.Arcade.prototype = {
10441051
// RIGHT
10451052
localOverlapX = body.right - tile.x;
10461053

1054+
if (localOverlapX > maxOverlapX)
1055+
{
1056+
localOverlapX = 0;
1057+
}
1058+
10471059
// Distance check
10481060
if (localOverlapX <= body.deltaX())
10491061
{
@@ -1059,6 +1071,12 @@ Phaser.Physics.Arcade.prototype = {
10591071
// UP
10601072
localOverlapY = body.y - tile.bottom;
10611073

1074+
// negatives
1075+
if (localOverlapY < -maxOverlapY)
1076+
{
1077+
localOverlapY = 0;
1078+
}
1079+
10621080
// Distance check
10631081
if (localOverlapY >= body.deltaY())
10641082
{
@@ -1073,6 +1091,11 @@ Phaser.Physics.Arcade.prototype = {
10731091
// DOWN
10741092
localOverlapY = body.bottom - tile.y;
10751093

1094+
if (localOverlapY > maxOverlapY)
1095+
{
1096+
localOverlapY = 0;
1097+
}
1098+
10761099
if (localOverlapY <= body.deltaY())
10771100
{
10781101
console.log('m down overlapY', localOverlapY, body.deltaY(), this.game.time.physicsElapsed);
@@ -1164,6 +1187,11 @@ Phaser.Physics.Arcade.prototype = {
11641187
// LEFT
11651188
body.overlapX = body.x - tile.right;
11661189

1190+
if (body.overlapX < -maxOverlapX)
1191+
{
1192+
body.overlapX = 0;
1193+
}
1194+
11671195
if (body.overlapX >= body.deltaX())
11681196
{
11691197
console.log('left overlapX', body.overlapX, body.deltaX(), this.game.time.physicsElapsed);
@@ -1178,6 +1206,11 @@ Phaser.Physics.Arcade.prototype = {
11781206
// RIGHT
11791207
body.overlapX = body.right - tile.x;
11801208

1209+
if (body.overlapX > maxOverlapX)
1210+
{
1211+
body.overlapX = 0;
1212+
}
1213+
11811214
// Distance check
11821215
if (body.overlapX <= body.deltaX())
11831216
{
@@ -1193,6 +1226,11 @@ Phaser.Physics.Arcade.prototype = {
11931226
// UP
11941227
body.overlapY = body.y - tile.bottom;
11951228

1229+
if (body.overlapY < -maxOverlapY)
1230+
{
1231+
body.overlapY = 0;
1232+
}
1233+
11961234
// Distance check
11971235
if (body.overlapY >= body.deltaY())
11981236
{
@@ -1207,6 +1245,11 @@ Phaser.Physics.Arcade.prototype = {
12071245
// DOWN
12081246
body.overlapY = body.bottom - tile.y;
12091247

1248+
if (body.overlapY > maxOverlapY)
1249+
{
1250+
body.overlapY = 0;
1251+
}
1252+
12101253
if (body.overlapY <= body.deltaY())
12111254
{
12121255
console.log('down overlapY', body.overlapY, body.deltaY(), this.game.time.physicsElapsed);

0 commit comments

Comments
 (0)