phaser/src/physics/arcade/GetOverlapY.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2019-03-21 17:24:26 +00:00
var CollisionInfo = require('./CollisionInfo');
var CONST = require('./const');
2019-03-11 17:28:23 +00:00
2018-02-09 03:44:23 +00:00
/**
*
2018-02-09 03:44:23 +00:00
*
* @function Phaser.Physics.Arcade.GetOverlapY
2019-03-21 17:24:26 +00:00
* @since 3.17.0
2018-02-09 03:44:23 +00:00
*
2018-10-19 16:45:05 +00:00
* @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).
2018-02-09 03:44:23 +00:00
*
2019-03-21 17:24:26 +00:00
* @return {CollisionInfo} A Collision Info object.
2018-02-09 03:44:23 +00:00
*/
2017-11-09 15:30:44 +00:00
var GetOverlapY = function (body1, body2, overlapOnly, bias)
{
if (overlapOnly === undefined) { overlapOnly = false; }
if (bias === undefined) { bias = 0; }
2019-03-21 17:24:26 +00:00
var collisionInfo = CollisionInfo.get(body1, body2, overlapOnly, bias);
2019-03-21 17:24:26 +00:00
if (!overlapOnly)
{
2019-03-21 17:24:26 +00:00
if (collisionInfo.face === CONST.FACING_UP)
{
2019-03-21 17:24:26 +00:00
console.log('GetOverlapY topFace');
2019-03-21 17:24:26 +00:00
if (collisionInfo.body1 === body1)
{
body1.setTouchingUp();
body2.setTouchingDown();
body1.setBlockedUp(collisionInfo);
body2.setBlockedDown(collisionInfo);
}
}
2019-03-21 17:24:26 +00:00
else if (collisionInfo.face === CONST.FACING_DOWN)
2019-03-11 17:28:23 +00:00
{
2019-03-21 17:24:26 +00:00
console.log('GetOverlapY bottomFace');
2019-03-21 17:24:26 +00:00
if (collisionInfo.body1 === body1)
{
body1.setTouchingDown();
body2.setTouchingUp();
2019-03-15 19:22:42 +00:00
2019-03-21 17:24:26 +00:00
body1.setBlockedDown(collisionInfo);
body2.setBlockedUp(collisionInfo);
}
2019-03-11 17:28:23 +00:00
}
}
2019-03-11 17:28:23 +00:00
2019-03-21 17:24:26 +00:00
return collisionInfo;
};
module.exports = GetOverlapY;