Skip to content
zz85 edited this page Aug 28, 2011 · 5 revisions

Welcome to the sparks.js wiki!

Sparks.js is a javascript particle engine along the likes of Flint and StarDust particle engines. It uses the awesome javascript libraries Three.js and Tween.js

There isn't much documentation out there at the moment, but feel free to check out the examples and drop any questions.

To create an emitter, var sparksEmitter = new SPARKS.Emitter(new SPARKS.SteadyCounter(160)); SPARKS.SteadyCounter tells the Emitter to produce 160 particles in a second.

Initializers

All particles created in the system would be initialized. sparksEmitter.addInitializer(new SPARKS.Position( new SPARKS.PointZone( new THREE.Vector3(0,0,0) ) ) ); This particle emitter initialize all particles with a position from a zone point, specifically at coordinates (0,0,0)

sparksEmitter.addInitializer(new SPARKS.Lifetime(4,5)); Set a random lifetime each particle, between 4 to 5 seconds

sparksEmitter.addInitializer(new SPARKS.Target(null, callback)); This initializer runs the callback, and sets the return result of the callback to the particle's target.

sparksEmitter.addInitializer(new SPARKS.Velocity(new SPARKS.PointZone(new THREE.Vector3(0,100,00)))); This assigns a velocity to the particle, which moves units of 0 along x, 100 units along y, and 0 along z axis.

Actions

sparksEmitter.addAction(new SPARKS.Age()); Every time the particle engine updates, this ages the particle, and removes it if its dead.

sparksEmitter.addAction(new SPARKS.Move()); This moves the particle based on its velocity and acceleration

sparksEmitter.addAction(new SPARKS.RandomDrift(500,500,0)); This drifts the particle in a random amount of units in a second.

Callbacks

Use callbacks to tap into the particle events sparksEmitter.addCallback("created", onParticleCreated); sparksEmitter.addCallback("initialized", onParticleInitialized); sparksEmitter.addCallback("dead", onParticleDead);

Running

sparksEmitter.start(); Run the engine using its built in timer.