diff --git a/src/physics/arcade/CheckOverlapY.js b/src/physics/arcade/CheckOverlapY.js index fb60034cd..24580db97 100644 --- a/src/physics/arcade/CheckOverlapY.js +++ b/src/physics/arcade/CheckOverlapY.js @@ -4,61 +4,51 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ -var IntersectsRect = require('./IntersectsRect'); +var CollisionInfo = require('./CollisionInfo'); +var CONST = require('./const'); /** - * Calculates and returns the vertical overlap between two arcade physics bodies. - * - * We know the bodies are intersecting based on a previous check, so the point of this function - * is to determine which face the overlap is occurring on and at what depth. + * Takes a CollisionInfo object and tests to see if the two bodies are still intersecting / touching. * * @function Phaser.Physics.Arcade.CheckOverlapY * @since 3.17.0 * * @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate. * @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate. - * @param {number} [padding=0] - * * @return {boolean} */ -var CheckOverlapY = function (body1, body2, padding) +var CheckOverlapY = function (body, collisionInfo) { - if (padding === undefined) { padding = 0; } + collisionInfo = CollisionInfo.update(collisionInfo); - var distance1 = body1.bottom - body2.y; - var distance2 = body2.bottom - body1.y; + var face = collisionInfo.face; + var body1 = collisionInfo.body1; + var body2 = collisionInfo.body2; - var prevDistance1 = (body1.prev.y + body1.height) - body2.prev.y; - var prevDistance2 = (body2.prev.y + body2.height) - body1.prev.y; - - var topFace = (distance1 > distance2 && prevDistance1 > prevDistance2); - - var intersects = IntersectsRect(body1, body2, padding); - - if (intersects && !topFace) + if (face === CONST.FACING_UP) { - if (body1.checkCollision.up && body2.checkCollision.down) - { - body1.setTouchingDown(); - body2.setTouchingUp(); + // console.log('CheckOverlapY topFace from', body.gameObject.name, 'body1 is', body1.gameObject.name, 'touching', collisionInfo.touching, 'inter', collisionInfo.intersects, 'oy', collisionInfo.overlapY); + // console.log('body1', body1.x, body1.right, body1.y, body1.bottom, 'body2', body2.x, body2.right, body2.y, body2.bottom); - body1.setBlockedDown(body2, false); - body2.setBlockedUp(body1, false); - } + body1.setTouchingUp(); + body2.setTouchingDown(); + + body1.setBlockedUp(); + body2.setBlockedDown(); } - else if (intersects && topFace) + else if (face === CONST.FACING_DOWN) { - if (body1.checkCollision.down && body2.checkCollision.up) - { - body1.setTouchingUp(); - body2.setTouchingDown(); + // console.log('CheckOverlapY bottomFace from', body.gameObject.name, 'body1 is', body1.gameObject.name); - body1.setBlockedUp(body2, false); - body2.setBlockedDown(body1, false); - } + body1.setTouchingDown(); + body2.setTouchingUp(); + + body1.setBlockedDown(); + body2.setBlockedUp(); } - return intersects; + return collisionInfo.touching; }; module.exports = CheckOverlapY; diff --git a/src/physics/arcade/GetOverlapY.js b/src/physics/arcade/GetOverlapY.js index 76f0bf093..fa0bb74e7 100644 --- a/src/physics/arcade/GetOverlapY.js +++ b/src/physics/arcade/GetOverlapY.js @@ -4,110 +4,60 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ -var IntersectsRect = require('./IntersectsRect'); +var CollisionInfo = require('./CollisionInfo'); +var CONST = require('./const'); /** - * Calculates and returns the vertical overlap between two arcade physics bodies. * - * We know the bodies are intersecting based on a previous check, so the point of this function - * is to determine which face the overlap is occurring on and at what depth. * * @function Phaser.Physics.Arcade.GetOverlapY - * @since 3.0.0 + * @since 3.17.0 * * @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate. * @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate. * @param {boolean} [overlapOnly] - Is this an overlap only check, or part of separation? * @param {number} [bias] - A value added to the delta values during collision checks. Increase it to prevent sprite tunneling (sprites passing through each other instead of colliding). * - * @return {number[]} An array containing the amount of overlap in element 0 and the face of body1 in element 1 (true = bottom, false = top). + * @return {CollisionInfo} A Collision Info object. */ var GetOverlapY = function (body1, body2, overlapOnly, bias) { if (overlapOnly === undefined) { overlapOnly = false; } if (bias === undefined) { bias = 0; } - var overlap = 0; + var collisionInfo = CollisionInfo.get(body1, body2, overlapOnly, bias); - // var maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + bias; - - var distance1 = body1.bottom - body2.y; - var distance2 = body2.bottom - body1.y; - - var prevDistance1 = (body1.prev.y + body1.height) - body2.prev.y; - var prevDistance2 = (body2.prev.y + body2.height) - body1.prev.y; - - var embedded = false; - - var topFace = (distance1 > distance2 && prevDistance1 > prevDistance2); - - var intersects = IntersectsRect(body1, body2); - - if (!topFace) + if (!overlapOnly) { - // body1 bottom is touching body2 top - if (intersects) - { - overlap = distance1; - } - - if (!body1.checkCollision.down || !body2.checkCollision.up) - { - overlap = 0; - intersects = false; - } - - if (!overlapOnly) - { - console.log('GetOverlapY !topFace'); - - body1.setTouchingDown(); - body2.setTouchingUp(); - - body1.setBlockedDown(body2, intersects); - body2.setBlockedUp(body1, intersects); - } - } - else - { - // body1 top is touching body2 bottom - if (intersects) - { - overlap = distance2; - } - - if (!body1.checkCollision.up || !body2.checkCollision.down) - { - overlap = 0; - intersects = false; - } - - if (!overlapOnly) + if (collisionInfo.face === CONST.FACING_UP) { console.log('GetOverlapY topFace'); - body1.setTouchingUp(); - body2.setTouchingDown(); + if (collisionInfo.body1 === body1) + { + body1.setTouchingUp(); + body2.setTouchingDown(); + + body1.setBlockedUp(collisionInfo); + body2.setBlockedDown(collisionInfo); + } + } + else if (collisionInfo.face === CONST.FACING_DOWN) + { + console.log('GetOverlapY bottomFace'); - body1.setBlockedUp(body2, intersects); - body2.setBlockedDown(body1, intersects); + if (collisionInfo.body1 === body1) + { + body1.setTouchingDown(); + body2.setTouchingUp(); + + body1.setBlockedDown(collisionInfo); + body2.setBlockedUp(collisionInfo); + } } } - // Resets the overlapY to zero if there is no overlap, or to the actual pixel value if there is - body1.overlapY = overlap; - body2.overlapY = overlap; - - if (embedded) - { - // We let the block resolution move it - overlap = 0; - - body1.embedded = embedded; - body2.embedded = embedded; - } - - return { overlap: overlap, topFace: topFace, intersects: intersects }; + return collisionInfo; }; module.exports = GetOverlapY;