Skip to content

Commit 070e33f

Browse files
committed
ArcadePhysics.overlap has been updated so that the Body.overlapX/Y properties are set to the amount the two bodies overlapped by. Previously they were zero and only populated during the separation phase, but now the data is available for just overlap checks as well. You can then use these values in your ovrelap callback as required - note that they are changed for every check, so a Sprite overlap tested against 10 other sprites will have the overlapX/Y values updated 10 times in a single collision pass, so you can only safely use the values in the callback (phaserjs#641)
1 parent 6784c3a commit 070e33f

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Version 2.1.0 - "Cairhien" - -in development-
135135
* ScaleManager.hasResized signal has been removed. Use ScaleManager.setResizeCallback instead.
136136
* The World bounds can now be set to any size, including smaller than the game dimensions. Before it was locked to a minimum size of the game canvas, but it can now be anything.
137137
* ScaleManager.orientationSprite has been removed because it never displayed correctly anyway (it would be distorted by the game scale), it will be bought back in a future version by way of a custom orientation state.
138+
* ArcadePhysics.overlap has been updated so that the Body.overlapX/Y properties are set to the amount the two bodies overlapped by. Previously they were zero and only populated during the separation phase, but now the data is available for just overlap checks as well. You can then use these values in your ovrelap callback as required - note that they are changed for every check, so a Sprite overlap tested against 10 other sprites will have the overlapX/Y values updated 10 times in a single collision pass, so you can only safely use the values in the callback (#641)
138139

139140
### Bug Fixes
140141

src/physics/arcade/World.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -784,13 +784,8 @@ Phaser.Physics.Arcade.prototype = {
784784
return false;
785785
}
786786

787-
if (overlapOnly)
788-
{
789-
// We already know they intersect from the check above, and we don't need separation, so ...
790-
return true;
791-
}
792-
793787
// Do we separate on x or y first?
788+
794789
// If we weren't having to carry around so much legacy baggage with us, we could do this properly. But alas ...
795790
if (this.forceX || Math.abs(this.gravity.y + body1.gravity.y) < Math.abs(this.gravity.x + body1.gravity.x))
796791
{
@@ -801,7 +796,15 @@ Phaser.Physics.Arcade.prototype = {
801796
this._result = (this.separateY(body1, body2, overlapOnly) || this.separateX(body1, body2, overlapOnly));
802797
}
803798

804-
return this._result;
799+
if (overlapOnly)
800+
{
801+
// We already know they intersect from the check above, but by this point we know they've now had their overlapX/Y values populated
802+
return true;
803+
}
804+
else
805+
{
806+
return this._result;
807+
}
805808

806809
},
807810

@@ -905,12 +908,13 @@ Phaser.Physics.Arcade.prototype = {
905908
}
906909
}
907910

911+
// Resets the overlapX to zero if there is no overlap, or to the actual pixel value if there is
912+
body1.overlapX = this._overlap;
913+
body2.overlapX = this._overlap;
914+
908915
// Then adjust their positions and velocities accordingly (if there was any overlap)
909916
if (this._overlap !== 0)
910917
{
911-
body1.overlapX = this._overlap;
912-
body2.overlapX = this._overlap;
913-
914918
if (overlapOnly || body1.customSeparateX || body2.customSeparateX)
915919
{
916920
return true;
@@ -1020,12 +1024,13 @@ Phaser.Physics.Arcade.prototype = {
10201024
}
10211025
}
10221026

1027+
// Resets the overlapY to zero if there is no overlap, or to the actual pixel value if there is
1028+
body1.overlapY = this._overlap;
1029+
body2.overlapY = this._overlap;
1030+
10231031
// Then adjust their positions and velocities accordingly (if there was any overlap)
10241032
if (this._overlap !== 0)
10251033
{
1026-
body1.overlapY = this._overlap;
1027-
body2.overlapY = this._overlap;
1028-
10291034
if (overlapOnly || body1.customSeparateY || body2.customSeparateY)
10301035
{
10311036
return true;

0 commit comments

Comments
 (0)