Sketch with classes implementation in a Reactjs project

Those are parameters w/ a default value, which takes place when the parameter is undefined.

That is, if we pass an argument to the parameter world only, the parameter p is gonna be initialized w/ the value p5.instance instead.

Actually p5.instance is irrelevant for this sketch b/c it holds the p5 reference of a global mode sketch.

Since this Matter.js sketch version is coded in instance mode only, p5.instance is always undefined.

Therefore we’ve always gotta pass the sketch’s p5 reference as the 2nd argument.

The original non-Matter.js had both global & instance mode versions.

So the global mode sketch could opt out to pass the 2nd argument if it chooses so.

BtW, p5js got a 3rd-party library called p5-matter which bundles Matter.js:
PalmerPaul.com/p5-matter

1 Like