Skip to content

v9.20.0

Compare
Choose a tag to compare
@Prozi Prozi released this 01 Nov 03:51
· 7 commits to master since this release

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.)