奇怪的javascript实例化

奇怪的javascript实例化,javascript,webgl,instantiation,Javascript,Webgl,Instantiation,我正在尝试实现Stemkoskis的优秀粒子引擎(),但是使用了他的“类”的多个实例。但问题是,当添加多个实例时,所有其他实例都会获取最后添加的关于tween size(sizeTween)的实例属性 以下是他的消息来源: 和实例化: 我尝试用谷歌搜索javascript中所谓的“类”的知识,所有这些似乎都与Tween实例化类有关,所有“类”都使用“this”指针。但我不能实例化两个不同的对象,这仍然没有意义。我想知道它是否与着色器有关,但这也没有意义,因为我可以实例化两种不同类型的粒子,但

我正在尝试实现Stemkoskis的优秀粒子引擎(),但是使用了他的“类”的多个实例。但问题是,当添加多个实例时,所有其他实例都会获取最后添加的关于tween size(sizeTween)的实例属性

以下是他的消息来源:

和实例化:

我尝试用谷歌搜索javascript中所谓的“类”的知识,所有这些似乎都与Tween实例化类有关,所有“类”都使用“this”指针。但我不能实例化两个不同的对象,这仍然没有意义。我想知道它是否与着色器有关,但这也没有意义,因为我可以实例化两种不同类型的粒子,但似乎两者之间保持不变

我只是想知道是否有人可以给我一个提示,如果他的代码有一些问题,使多个实例不能是唯一的?(我试过火球和雪(在演示中)

任何提示都很好。今天花了8个小时,我还是不明白

这是我的代码,我使用ParticleEngine.js文件中的代码

// Clouds
var cloud = new Cloud();
cloud.Create(0,0,0, 4, scene);
objects.push(cloud); // this makes the Draw function gets called in each instance

// Sun
var sun = new Sun();
sun.Create(0,200,0, scene);
objects.push(sun); // this makes the Draw function gets called in each instance

// My own classes
// Baseclass
function Object3D() {
    this.mesh;

    Object3D.prototype.GetObject = function() {
        return this.mesh;
    };

    Object3D.prototype.Draw = function() {
        //draw object
    };
}

// Class that creates the snow
function Cloud() {
    Object3D.call(this);

    Cloud.prototype.Create = function(x ,y ,z, s, scene) {
            var engine = new ParticleEngine();
            engine.setValues(
                {positionStyle    : Type.CUBE,
                 positionBase     : new THREE.Vector3( 0, 0, 0 ),
                 positionSpread   : new THREE.Vector3( 200, 0, 200 ),
                 positionRadius : 0.1,

                 velocityStyle    : Type.CUBE,
                 velocityBase     : new THREE.Vector3( 0, -300, 0 ),
                 velocitySpread   : new THREE.Vector3( 150, 20, 150 ),
                 accelerationBase : new THREE.Vector3( 0, -5,0 ),

                 sizeTween    : new Tween( [0, 0.25], [1, 10] ),
                 colorBase   : new THREE.Vector3(0.66, 1.0, 0.9), // H,S,L
                 opacityTween : new Tween( [2, 3], [0.8, 0] ),
                 blendStyle   : THREE.AdditiveBlending,

                 angleBase               : 0,
                 angleSpread             : 720,
                 angleVelocityBase       :  0,
                 angleVelocitySpread     : 60,

                 particleTexture : THREE.ImageUtils.loadTexture( 'textures/snowflake.png' ),

                 particlesPerSecond : Math.random()*50+100,
                 particleDeathAge   : 10.5,
                 // emitterDeathAge    : 60
                });
            engine.initialize();
            this.engine = engine;
    };

    Cloud.prototype.Draw = function(time) {
            this.engine.update(time * 0.00005);
    };
}
Cloud.prototype = new Object3D();
Cloud.prototype.constructor = Cloud;

// Class that creates the fireball effect
function Sun() {
    Object3D.call(this);

    Sun.prototype.Create = function(x, y, z, scene) {
        var sunEngine = new ParticleEngine();

        sunEngine.setValues(
            {
                positionStyle  : Type.SPHERE,
                positionBase   : new THREE.Vector3(0, 200, 0),
                positionRadius : 2,

                sizeTween    : new Tween( [0, 0.4], [1, 150] ),
                opacityTween : new Tween( [0.7, 1], [1, 0] ),
                colorBase    : new THREE.Vector3(0.02, 1, 0.4),
                blendStyle   : THREE.AdditiveBlending,  

                velocityStyle : Type.SPHERE,
                speedBase     : 40,
                speedSpread   : 8,

                particleTexture : THREE.ImageUtils.loadTexture( 'textures/smokeparticle.png' ),

                particlesPerSecond : 60,
                particleDeathAge: 1.5,
                //emitterDeathAge    : 60
            });
        sunEngine.initialize();
        this.sunEngine = sunEngine;
    };


    Sun.prototype.Draw = function(time) {
        this.sunEngine.update(time * 0.00005 );
    };
}
Sun.prototype = new Object3D();
Sun.prototype.constructor = Sun;
在第一个实例(云/雪)中,我设置:

然后我用这个属性启动“Sun”类:

sizeTween    : new Tween( [0, 0.4], [1, 150] ),

首先启动的云会得到与上次添加的相同的大小值。这是我遇到的核心问题。

如果您向我们提供一些显示您尝试的代码,会有所帮助。我添加了代码链接。我包含了重要部分。您需要检查对象的原型链,因为它看起来像一些Tween属性正在分配给原型而不是实例。这是主要问题。谢谢,现在它可以工作了。
sizeTween    : new Tween( [0, 0.4], [1, 150] ),