Quick background I am using p5.js in instance mode (long story why I have to use instance mode, so just pretend its required) and I want to write a simple library that contains stuff that I do in all my sketches, for example print a title. Can someone help me out with this?
My main sketch is instanced so it looks something like this (but with more stuff…):
const sketchStuff = (p) => {
p.draw = () => {
p.background(360, 3);
p.drawCrap()
}
}
new p5(sketchStuff );
This is more to it, but you get the idea…
Anyway so I want to define functions in a separate library that I can call. For example in the above code I have a function called drawCrap(). I haven’t been successful so far, but here’s where I started (this would be saved in a .js file and linked in my html file:
p5.prototype.drawCrap = function() {
fill(0, 102, 153);
text("Title", 8, 22);
}
My instance sketch stuff works fine, but my library function doesnt work, so what do I need to change in my library file to make it work?
Thanks and sorry for my crappy example and my poor p5 skills.
Update: the solution was that I was missing “this.” In from of the p5 library calls like fill and text