这可能有点过于具体,但也许有人在这里有扩展toxiclib.js的粒子类的经验?
我一直在:
TypeError: this.setWeight is not a function
我做的很简单(我正在使用Processing.js):
class Particle extends VerletParticle2D {
Particle(float x, float y) {
super(x,y);
}
void display() {
stroke(0);
ellipse(x,y,16,16);
}
}
答案 0 :(得分:1)
Processing.js和其他库之间的继承尚未解决。有一个解决方法。
首先,要通过其完整命名空间引用VerletParticle2D:
class Particle extends toxi.physics2d.VerletParticle2D
第二部分是把它添加到toxiclibs.js'构造为VerletParticle2D(在写此的时间,即构建/ toxiclibs.js的行#9941):
if(!(this instanceof VerletParticle2D)){
return new VerletParticle2D(x,y,w);
}
第三部分是在定义课程后的任何地方添加这两行。不幸的是,这两行不适合Processing IDE:
Particle.prototype = new toxi.physics2d.VerletParticle2D();
Particle.prototype.constructor = Particle;
您可以将这3种模式应用于任何其他类以扩展它们。 此外,Processing 2.0 Alpha 5发布了一项新功能,可以在随附的.jar旁边拉一个.js文件。因此,如果将toxiclibs.js放在toxiclibscore.jar旁边并重命名,它将与您的草图一起导出。这样可以更容易地为扩展类创建一个版本。
我上传了网页导出的草图,其中包含修改后的toxiclibscore.js文件:http://haptic-data.com/toxiclibsjs/misc/ToxiclibsjsExtend.zip
祝你好运!