- Not sure if I understood your example above.
- Anyways, a p5js library needs to work whether a sketch is using global or instance mode.
- And a sure way to accomplish such flexibility is for the library to request the sketch’s p5 reference from its user.
- As an example, take a look at how I instantiate classes Ball & Chamber:
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/sketch/sketch.js#L30-L31
https://github.com/GoSubRoutine/Ball-in-the-Chamber/blob/2.0.5/instance/sketch/sketch.js#L33-L40
- Even though the “sketch.js” above is using instance mode, if I decide to convert it to global mode, the 2 code blocks above would be exactly the same!
- That is, classes Ball & Chamber work regardless the current mode a sketch is using, b/c they request the sketch’s reference as their 1st parameter!