Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Emitte particles from one point to another ?


Recommended Posts

Well, let me try to give you an idea. Have to warn it's coming initially from a 1.1.3 version game.

Main point: the emitter is just a group. So, for example, with emitter em you can run:

em.setAll('alpha', 0.5);em.forEach(myFunction, myParameter);

So, for example, once particles are emitted, you should be able to set up a tween for moving every particle to the desired location. Not sure how to do it correctly with particles that are not emitted all in one shot though.

Also I thought about something like MoveToPointer, but perhaps enabling even Arcade physics for emitted particles is a bad idea.

Link to comment
Share on other sites

i'm doing this:  (and i think you could adapt it to your needs)


in create function:

 emitter = game.add.emitter(0, 0, 200);    emitter.makeParticles('smoke',0,200,true,true);    emitter.enableBody = true;       emitter.physicsBodyType = Phaser.Physics.P2JS;    emitter.setYSpeed(250, 0);

(you don't need to enable body, physics type and speed.. this is just for my testcase where i want the smoke to move down when emitted..


and then (when needed):

function particleBurst(player) {    emitter.x = player.body.x;    emitter.y = player.body.y;    emitter.start(true, 2500, null, 10);   //explode, lifespan, .. , count    emitter.forEach(setUp, this);}

this starts the emitter and calls setup for every particle:

function setUp(particle){    if (!particle.exists) {particle.alpha=1;}    game.add.tween(particle).to({ alpha: 0 }, 1000, Phaser.Easing.Cubic.Out, true);    game.add.tween(particle.scale).to({ x: 2,y:2 }, 1000, Phaser.Easing.Cubic.Out, true);}

this sets alpha for ever nonexistant particle to 1 (because i need to start every particle completely visible)

and then it tweens the particles to alpha 0 and scales them to double their size 


(i'm creating wonderfull looking smoke with this ^^)


Link to comment
Share on other sites

Thanks valueerror !



I've made my function like this :

function emitteParticuleTo(x, y, xDest, yDest, nb, tm, particle){	var emitter = game.add.emitter(x, y, 100);	emitter.makeParticles(particle);	emitter.minParticleScale = 0.2;	emitter.maxParticleScale = 0.4;	emitter.start(true, tm, 20, nb);	setTimeout(function(){ 	    emitter.forEach(function(particle){		particle.gravity = 0		var tw = game.add.tween(particle).to({ x: xDest, y: yDest}, 500, Phaser.Easing.Linear.None, true, 0, false);		tw.onComplete.addOnce(function(){ particle.kill(); }, this);	    }, this, false);	}, 700);    }

And it work like I want it to work, anyway your example is realy interesting.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...