It may be a bit too specific, but maybe someone here has experience extending the particle class of toxiclib.js?
I keep getting:
TypeError: this.setWeight is not a function
I am doing a very simple thing (I am using Processing.js):
class Particle extends VerletParticle2D {
Particle(float x, float y) {
super(x,y);
}
void display() {
stroke(0);
ellipse(x,y,16,16);
}
}
Inheritance between Processing.js and other libraries is not all figured out yet. There is a workaround.
First thing is to refer to VerletParticle2D by its full namespace:
Second part is to add this to toxiclibs.js’ constructor for VerletParticle2D (at the time of writing this, that is line #9941 of build/toxiclibs.js):
Third part is to add these 2 lines anywhere after you have defined your class. Unfortunately these 2 lines won’t play nice with the Processing IDE:
You can apply these 3 patterns to any other class as well to extend them.
Also, Processing 2.0 Alpha 5 released a new feature that will pull a .js file next to an accompanying .jar. So if you place toxiclibs.js next to toxiclibscore.jar and rename it, it will get exported with your sketch. This will make it easier to have one version that you make some modifications to for extending classes.
I have uploaded the web-exported sketch, with the modified toxiclibscore.js file here: http://haptic-data.com/toxiclibsjs/misc/ToxiclibsjsExtend.zip
best of luck!