UNPKG

arcade-physics

Version:
76 lines 3.13 kB
"use strict"; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Factory = void 0; const Body_1 = require("./Body"); const StaticBody_1 = require("./StaticBody"); class Factory { /** * The Arcade Physics Factory allows you to easily create Arcade Physics enabled Game Objects. * Objects that are created by this Factory are automatically added to the physics world. * * @param world The Arcade Physics World instance. */ constructor(world) { this.world = world; /** A reference to the Scene this Arcade Physics instance belongs to. */ this.scene = world.scene; /** A reference to the Scene.Systems this Arcade Physics instance belongs to. */ this.sys = world.scene.sys; } /** Creates a new Dynamic Arcade Body. */ body(x, y, width = 64, height = 64) { const body = new Body_1.Body(this.world, x, y, width, height); this.world.add(body); return body; } /** Creates a new Static Arcade Physics Body. */ staticBody(x, y, width = 64, height = 64) { const staticBody = new StaticBody_1.StaticBody(this.world, x, y, width, height); this.world.add(staticBody); return staticBody; } /** * Creates a new Arcade Physics Collider object. * * @param body1 - The first object to check for collision. * @param body2 - The second object to check for collision. * @param [collideCallback] - The callback to invoke when the two objects collide. * @param [processCallback] - The callback to invoke when the two objects collide. Must return a boolean. * @param [callbackContext] - The scope in which to call the callbacks. * * @return The Collider that was created. */ collider(body1, body2, collideCallback, processCallback, callbackContext) { return this.world.addCollider(body1, body2, collideCallback, processCallback, callbackContext); } /** * Creates a new Arcade Physics Collider Overlap object. * * @param body1 - The first object to check for overlap. * @param body2 - The second object to check for overlap. * @param [collideCallback] - The callback to invoke when the two objects collide. * @param [processCallback] - The callback to invoke when the two objects collide. Must return a boolean. * @param [callbackContext] - The scope in which to call the callbacks. * * @return The Collider that was created. */ overlap(body1, body2, collideCallback, processCallback, callbackContext) { return this.world.addOverlap(body1, body2, collideCallback, processCallback, callbackContext); } /** Destroys this Factory. */ destroy() { // @ts-ignore this.world = null; // @ts-ignore this.scene = null; // @ts-ignore this.sys = null; } } exports.Factory = Factory; //# sourceMappingURL=Factory.js.map