-
Notifications
You must be signed in to change notification settings - Fork 2
Emitter
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
var emitter = new frb.Emitter(engineInstance);
-
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.
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;
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;
};