UNPKG

gibbon.js

Version:

Actor/Component system for use with pixi.js.

45 lines 1.26 kB
import { System } from "../system"; /** * */ export class BoundsDestroy extends System { /** * @property {(Actor)=>void} onExit - function to call when object * leaves bounds. If a function is specified, the object is not destroyed * automatically, but is removed from group. */ onExit; /** * @property {Rectangle} bounds - objects in system outside the bounds * will automatically be destroyed unless an onExit() function is specified. * If so, the onExit function will be called instead. */ bounds; /** * * @param {Game} game * @param {Container} clip * @param {Rectangle} rect */ constructor(rect, clip) { super(clip); this.bounds = rect; } update() { for (let i = this.objects.length - 1; i >= 0; i--) { const o = this.objects[i]; if (o.isDestroyed) { continue; } const pos = o.position; if (this.bounds.contains(pos.x, pos.y) === false) { if (this.onExit) this.onExit(o); else { o.destroy(); } } } } } //# sourceMappingURL=boundsDestroy.js.map