arcade-physics
Version:
Use Arcade Physics without Phaser.
66 lines • 2.6 kB
JavaScript
"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.Collider = void 0;
class Collider {
/**
* An Arcade Physics Collider will automatically check for collision, or overlaps, between two objects
* every step. If a collision, or overlap, occurs it will invoke the given callbacks.
*
* @param world The world in which the bodies will collide.
* @param overlapOnly Whether to check for collisions or overlaps.
* @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 If a processCallback exists it must return true or collision checking will be skipped.
* @param callbackContext The context the collideCallback and processCallback will run in.
*/
constructor(world, overlapOnly, body1, body2, collideCallback, processCallback, callbackContext) {
this.world = world;
this.overlapOnly = overlapOnly;
this.body1 = body1;
this.body2 = body2;
this.collideCallback = collideCallback;
this.processCallback = processCallback;
this.callbackContext = callbackContext;
/** The name of the collider (unused by Phaser). */
this.name = '';
/** Whether the collider is active. */
this.active = true;
}
/**
* A name for the Collider.
*
* Phaser does not use this value, it's for your own reference.
*/
setName(name) {
this.name = name;
return this;
}
/** Called by World as part of its step processing, initial operation of collision checking. */
update() {
this.world.collideObjects(this.body1, this.body2, this.collideCallback, this.processCallback, this.callbackContext, this.overlapOnly);
}
/** Removes Collider from World and disposes of its resources. */
destroy() {
this.world.removeCollider(this);
this.active = false;
// @ts-ignore
this.world = null;
// @ts-ignore
this.body1 = null;
// @ts-ignore
this.body2 = null;
// @ts-ignore
this.collideCallback = null;
// @ts-ignore
this.processCallback = null;
this.callbackContext = null;
}
}
exports.Collider = Collider;
//# sourceMappingURL=Collider.js.map