UNPKG

arcade-physics

Version:
54 lines 2.62 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const OverlapRect_1 = __importDefault(require("./OverlapRect")); const Circle_1 = require("../../../geom/circle/Circle"); const CircleToCircle_1 = __importDefault(require("../../../geom/intersects/CircleToCircle")); const CircleToRectangle_1 = __importDefault(require("../../../geom/intersects/CircleToRectangle")); /** * This method will search the given circular area and return an array of all physics bodies that * overlap with it. It can return either Dynamic, Static bodies or a mixture of both. * * A body only has to intersect with the search area to be considered, it doesn't have to be fully * contained within it. * * If Arcade Physics is set to use the RTree (which it is by default) then the search is rather fast, * otherwise the search is O(N) for Dynamic Bodies. * * @function Phaser.Physics.Arcade.Components.OverlapCirc * @since 3.21.0 * * @param {number} x - The x coordinate of the center of the area to search within. * @param {number} y - The y coordinate of the center of the area to search within. * @param {number} radius - The radius of the area to search within. * @param {boolean} [includeDynamic=true] - Should the search include Dynamic Bodies? * @param {boolean} [includeStatic=false] - Should the search include Static Bodies? * * @return {(Phaser.Physics.Arcade.Body[]|Phaser.Physics.Arcade.StaticBody[])} An array of bodies that overlap with the given area. */ const OverlapCirc = function (world, x, y, radius, includeDynamic = true, includeStatic = false) { const bodiesInRect = (0, OverlapRect_1.default)(world, x - radius, y - radius, 2 * radius, 2 * radius, includeDynamic, includeStatic); if (bodiesInRect.length === 0) { return bodiesInRect; } const area = new Circle_1.Circle(x, y, radius); const circFromBody = new Circle_1.Circle(); const bodiesInArea = []; for (let i = 0; i < bodiesInRect.length; i++) { const body = bodiesInRect[i]; if (body.isCircle) { circFromBody.setTo(body.center.x, body.center.y, body.halfWidth); if ((0, CircleToCircle_1.default)(area, circFromBody)) { bodiesInArea.push(body); } } else if ((0, CircleToRectangle_1.default)(area, body)) { bodiesInArea.push(body); } } return bodiesInArea; }; exports.default = OverlapCirc; //# sourceMappingURL=OverlapCirc.js.map