v9.20.0
You can provide custom class to body create functions:
import { System, Polygon } from "detect-collisions";
const physics = new System();
class MyPolygon extends Polygon {
constructor(position, points, options) {
super(position, points, options);
this.foo = "bar";
}
}
// create minimal MyPolygon and insert to system
const myPolygon = physics.createPolygon({}, [{}], {}, MyPolygon);
// true
console.log(myPolygon.foo === "bar");
});
this may be useful for any customizations
last optional parameter of system.create*
is a class that extends the base class (extends Box for createBox, extends Circle for createCircle, etc.)