|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2019 Photon Storm Ltd. |
| 4 | + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var CollisionInfo = require('./CollisionInfo'); |
| 8 | +var CONST = require('./const'); |
| 9 | + |
| 10 | +/** |
| 11 | + * |
| 12 | + * |
| 13 | + * @function Phaser.Physics.Arcade.GetOverlap |
| 14 | + * @since 3.17.0 |
| 15 | + * |
| 16 | + * @param {Phaser.Physics.Arcade.Body} body1 - The first Body to separate. |
| 17 | + * @param {Phaser.Physics.Arcade.Body} body2 - The second Body to separate. |
| 18 | + * @param {boolean} [overlapOnly] - Is this an overlap only check, or part of separation? |
| 19 | + * @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). |
| 20 | + * |
| 21 | + * @return {CollisionInfo} A Collision Info object. |
| 22 | + */ |
| 23 | +var GetOverlap = function (body1, body2, overlapOnly, bias) |
| 24 | +{ |
| 25 | + if (overlapOnly === undefined) { overlapOnly = false; } |
| 26 | + if (bias === undefined) { bias = 0; } |
| 27 | + |
| 28 | + var collisionInfo = CollisionInfo.get(body1, body2, overlapOnly, bias); |
| 29 | + |
| 30 | + if (overlapOnly) |
| 31 | + { |
| 32 | + return collisionInfo; |
| 33 | + } |
| 34 | + |
| 35 | + if (collisionInfo.face === CONST.FACING_LEFT) |
| 36 | + { |
| 37 | + console.log('GetOverlapX leftFace'); |
| 38 | + |
| 39 | + if (collisionInfo.body1 === body1) |
| 40 | + { |
| 41 | + body1.setTouchingLeft(); |
| 42 | + body2.setTouchingRight(); |
| 43 | + |
| 44 | + body1.setBlockedLeft(collisionInfo); |
| 45 | + body2.setBlockedRight(collisionInfo); |
| 46 | + |
| 47 | + if (body2.isWorldBlockedLeft()) |
| 48 | + { |
| 49 | + body1.setHardBlockedLeft(); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + else if (collisionInfo.face === CONST.FACING_RIGHT) |
| 54 | + { |
| 55 | + console.log('GetOverlapX rightFace'); |
| 56 | + |
| 57 | + if (collisionInfo.body1 === body1) |
| 58 | + { |
| 59 | + body1.setTouchingRight(); |
| 60 | + body2.setTouchingLeft(); |
| 61 | + |
| 62 | + body1.setBlockedRight(collisionInfo); |
| 63 | + body2.setBlockedLeft(collisionInfo); |
| 64 | + |
| 65 | + if (body2.isWorldBlockedRight()) |
| 66 | + { |
| 67 | + body1.setHardBlockedRight(); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + else if (collisionInfo.face === CONST.FACING_UP) |
| 72 | + { |
| 73 | + console.log('GetOverlapY topFace'); |
| 74 | + |
| 75 | + if (collisionInfo.body1 === body1) |
| 76 | + { |
| 77 | + body1.setTouchingUp(); |
| 78 | + body2.setTouchingDown(); |
| 79 | + |
| 80 | + body1.setBlockedUp(collisionInfo); |
| 81 | + body2.setBlockedDown(collisionInfo); |
| 82 | + |
| 83 | + if (body2.isWorldBlockedUp()) |
| 84 | + { |
| 85 | + body1.setHardBlockedUp(); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + else if (collisionInfo.face === CONST.FACING_DOWN) |
| 90 | + { |
| 91 | + console.log('GetOverlapY bottomFace'); |
| 92 | + |
| 93 | + if (collisionInfo.body1 === body1) |
| 94 | + { |
| 95 | + body1.setTouchingDown(); |
| 96 | + body2.setTouchingUp(); |
| 97 | + |
| 98 | + body1.setBlockedDown(collisionInfo); |
| 99 | + body2.setBlockedUp(collisionInfo); |
| 100 | + |
| 101 | + if (body2.isWorldBlockedDown()) |
| 102 | + { |
| 103 | + body1.setHardBlockedDown(); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + return collisionInfo; |
| 109 | +}; |
| 110 | + |
| 111 | +module.exports = GetOverlap; |
0 commit comments