zz85 / sparks.js

a lightweight 3d particle engine in javascript, compatible with THREE.js and TWEEN.js
435 stars 47 forks source link

Start particle at a point in time #20

Closed whs closed 12 years ago

whs commented 12 years ago

I want the scene to starts with some particles already existing, just like when the particle system is already ran for few seconds.

Tried this code, but 100 interval doesn't seems to work. 1s does it but the user will see the initialization stage.

var i = setInterval(function(){ threexSparks._emitter.update(0.1); }, 1); 
setTimeout(function(i){
    clearInterval(i);
}, 100, i);
zz85 commented 12 years ago

you can pass in a custom time to the particle engine to simulate activity before rendering them. for example for ten seconds

emitter.update(10);

or you could do it with a loop, for more accurate results

for (i=0;i<100;i++) {
emitter.update(0.1
}
whs commented 12 years ago

That does the trick. Thanks!