Skip to content
Joel Martinez edited this page Jul 1, 2013 · 3 revisions

The Emitter class can be used to generate particles.

Sample: http://joelmartinez.github.io/flatredball-js/#emitter

Initialization

var emitter = new frb.Emitter(engineInstance);

Available Properties

  • position - this is a PositionedObject that controls the location of the emitter.
  • emitSprite(texture) - emits a Sprite using the given texture.
  • emitCircle(radius) - emits a Circle.

How To: Emit particles in random directions

        var newParticle = emitSprite("fire");

        // initialize particle
        var xRange = 100;
        var gravity = -150.5;
        var direction = {x: (Math.random() * xRange) - (xRange/2), y: Math.random() * 400};

        newParticle.xVelocity = direction.x;
        newParticle.yVelocity = direction.y;

        newParticle.yAcceleration = gravity;

How To: Fade particles over time

        var list = emitter.items();
        for (var i = 0; i < list.length; i++) {
            var particle = list.get(i);
            if (particle.alpha <= 0) { 
                emitter.pool.return(particle);
                continue;
            }

            particle.alpha -= 0.05;
        };
Clone this wiki locally