mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Removed responsibility for flag setting from overlay, also return a value all the time, not just in motion
This commit is contained in:
parent
e1f9e31e9f
commit
e27196ce52
1 changed files with 19 additions and 53 deletions
|
@ -4,11 +4,8 @@
|
|||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var CONST = require('./const');
|
||||
|
||||
/**
|
||||
* Calculates and returns the vertical overlap between two arcade physics bodies and sets their properties
|
||||
* accordingly, including: `touching.up`, `touching.down`, `touching.none` and `overlapY'.
|
||||
* Calculates and returns the vertical overlap between two arcade physics bodies.
|
||||
*
|
||||
* @function Phaser.Physics.Arcade.GetOverlapY
|
||||
* @since 3.0.0
|
||||
|
@ -16,7 +13,7 @@ var CONST = require('./const');
|
|||
* @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 another instead of colliding).
|
||||
* @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} The amount of overlap.
|
||||
*/
|
||||
|
@ -25,71 +22,40 @@ var GetOverlapY = function (body1, body2, overlapOnly, bias)
|
|||
var overlap = 0;
|
||||
var maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + bias;
|
||||
|
||||
if (body1._dy === 0 && body2._dy === 0)
|
||||
var body1Down = (body1._dy > body2._dy);
|
||||
|
||||
if (body1._dy === body2._dy)
|
||||
{
|
||||
// They overlap but neither of them are moving
|
||||
body1.embedded = true;
|
||||
body2.embedded = true;
|
||||
// Neither of them has a faster velocity, but we still need to separate them
|
||||
|
||||
// Try to figure it out based on overlap size
|
||||
var distance1 = body1.bottom - body2.y;
|
||||
var distance2 = body2.bottom - body1.y;
|
||||
|
||||
body1Down = (distance1 < distance2);
|
||||
}
|
||||
else if (body1._dy > body2._dy)
|
||||
|
||||
if (body1Down)
|
||||
{
|
||||
// Body1 is moving down and/or Body2 is moving up
|
||||
// body1 is moving down and body2 is either moving up, moving slower than body1, or static
|
||||
overlap = body1.bottom - body2.y;
|
||||
|
||||
if ((overlap > maxOverlap && !overlapOnly) || body1.checkCollision.down === false || body2.checkCollision.up === false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.none = false;
|
||||
body1.touching.down = true;
|
||||
|
||||
body2.touching.none = false;
|
||||
body2.touching.up = true;
|
||||
|
||||
if (body2.physicsType === CONST.STATIC_BODY)
|
||||
{
|
||||
body1.blocked.none = false;
|
||||
body1.blocked.down = true;
|
||||
}
|
||||
|
||||
if (body1.physicsType === CONST.STATIC_BODY)
|
||||
{
|
||||
body2.blocked.none = false;
|
||||
body2.blocked.up = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (body1._dy < body2._dy)
|
||||
else
|
||||
{
|
||||
// Body1 is moving up and/or Body2 is moving down
|
||||
// body1 is moving up and body2 is either moving down, moving slower than body1, or static
|
||||
overlap = body1.y - body2.bottom;
|
||||
|
||||
// console.log('body1 faster up', overlap);
|
||||
|
||||
if ((-overlap > maxOverlap && !overlapOnly) || body1.checkCollision.up === false || body2.checkCollision.down === false)
|
||||
{
|
||||
overlap = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
body1.touching.none = false;
|
||||
body1.touching.up = true;
|
||||
|
||||
body2.touching.none = false;
|
||||
body2.touching.down = true;
|
||||
|
||||
if (body2.physicsType === CONST.STATIC_BODY)
|
||||
{
|
||||
body1.blocked.none = false;
|
||||
body1.blocked.up = true;
|
||||
}
|
||||
|
||||
if (body1.physicsType === CONST.STATIC_BODY)
|
||||
{
|
||||
body2.blocked.none = false;
|
||||
body2.blocked.down = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Resets the overlapY to zero if there is no overlap, or to the actual pixel value if there is
|
||||
|
|
Loading…
Add table
Reference in a new issue