zz85 / sparks.js

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

SPARKS.SteadyCounter doesnt emit anything for rate <= 66 #4

Closed jeromeetienne closed 12 years ago

jeromeetienne commented 12 years ago

sparksEmitter = new SPARKS.Emitter(new SPARKS.SteadyCounter(67));

This will emit particles BUT

sparksEmitter = new SPARKS.Emitter(new SPARKS.SteadyCounter(66));

wont.

any rate <= 66 doesnt emit anything here

jeromeetienne commented 12 years ago

maybe this Math.floor is related

SPARKS.SteadyCounter.prototype.updateEmitter = function(emitter, time) { 
    return Math.floor(time * this.rate);
};
zz85 commented 12 years ago

ah yes.. that was a cheap way to calculate the number of particles in step, because of the high refresh loop, (maybe 100 times a second), the emitter can't emit a fraction of 1 every loop.

i could add a counter to track particles generated every second to ensure more accurate emission..

zz85 commented 12 years ago

fix for a more reliable SteadyCounter pushed.

https://github.com/zz85/sparks.js/compare/320980f498...790f7749ba

now it accept values of <60, even 1 or 0.5

jeromeetienne commented 12 years ago

excelent! thanks :)