I want to extend the p5.js library in order to have error text on various locations on the screen. I will be using it in different places throughout my app and I believe it's better to do this than duplicating the code.
For now, almost everything is working fine, except some properties. For example, if I access super.height
I'll get 0, while if I access this.height
I'll get the actual window height. But, when accessing this.height
I get an error saying that height
isn't defined in CustomP5, which is right, but at the same time confusing.
import * as p5 from 'p5';
export class CustomP5 extends p5 {
... // private fields not related to this issue
constructor(sketch, htmlElement) {
super(sketch, htmlElement);
// Set tooltip error variables
this.resetTooltipError();
}
setSetup(setupFunction) {
super.setup = () => {
setupFunction();
this.setupAdditional();
}
}
setDraw(drawFunction) {
super.draw = () => {
drawFunction();
this.drawAdditional();
};
}
showTooltipError() {
...
}
Is there a reason why super.height
, super.mouseX
, and super.mouseY
don't work, while super.draw
or super.mousePressed
are working correctly?
PS: I'm quite new to js and ts, so be patient if I'm wrong, please.