Skip to content

Commit 69eec0a

Browse files
committed
Fixed overlap method
1 parent c267662 commit 69eec0a

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/physics/matter-js/MatterPhysics.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -830,47 +830,48 @@ var MatterPhysics = new Class({
830830
* @method Phaser.Physics.Matter.MatterPhysics#overlap
831831
* @since 3.22.0
832832
*
833-
* @param {(MatterJS.Body|MatterJS.Body[])} body - The target body, or array of target bodies, to check.
834-
* @param {MatterJS.Body[]} [object2] - The second body, or array of bodies, to check. If falsey it will check against all bodis in the world.
833+
* @param {(MatterJS.Body|MatterJS.Body[])} target - The target body, or array of target bodies, to check.
834+
* @param {MatterJS.Body[]} [bodies] - The second body, or array of bodies, to check. If falsey it will check against all bodies in the world.
835835
* @param {ArcadePhysicsCallback} [overlapCallback] - An optional callback function that is called if the bodies overlap.
836836
* @param {ArcadePhysicsCallback} [processCallback] - An optional callback function that lets you perform additional checks against the two bodies if they overlap. If this is set then `overlapCallback` will only be invoked if this callback returns `true`.
837837
* @param {*} [callbackContext] - The context, or scope, in which to run the callbacks.
838838
*
839839
* @return {boolean} `true` if the target body intersects with _any_ of the bodies given, otherwise `false`.
840840
*/
841-
overlap: function (body, bodies, overlapCallback, processCallback, callbackContext)
841+
overlap: function (target, bodies, overlapCallback, processCallback, callbackContext)
842842
{
843843
if (overlapCallback === undefined) { overlapCallback = null; }
844844
if (processCallback === undefined) { processCallback = null; }
845845
if (callbackContext === undefined) { callbackContext = overlapCallback; }
846846

847-
if (!Array.isArray(body))
847+
if (!Array.isArray(target))
848848
{
849-
body = [ body ];
849+
target = [ target ];
850850
}
851851

852+
target = this.getMatterBodies(target);
852853
bodies = this.getMatterBodies(bodies);
853854

854855
var match = false;
855856

856-
for (var i = 0; i < body.length; i++)
857+
for (var i = 0; i < target.length; i++)
857858
{
858-
var target = body[i];
859+
var entry = target[i];
859860

860-
var collisions = Query.collides(target, bodies);
861+
var collisions = Query.collides(entry, bodies);
861862

862863
for (var c = 0; c < collisions.length; c++)
863864
{
864865
var info = collisions[c];
865-
var bodyB = (info.bodyA.id === target.id) ? info.bodyB : info.bodyA;
866+
var bodyB = (info.bodyA.id === entry.id) ? info.bodyB : info.bodyA;
866867

867-
if (!processCallback || processCallback.call(callbackContext, target, bodyB, info))
868+
if (!processCallback || processCallback.call(callbackContext, entry, bodyB, info))
868869
{
869870
match = true;
870871

871872
if (overlapCallback)
872873
{
873-
overlapCallback.call(callbackContext, target, bodyB, info);
874+
overlapCallback.call(callbackContext, entry, bodyB, info);
874875
}
875876
else if (!processCallback)
876877
{

0 commit comments

Comments
 (0)