Jump to content

Change particle velocity after emitter start


Recommended Posts

I'm creating an emitter with 1 particle (for the sake of example) and I'm starting the emitter using flow.

    var emitter = game.add.emitter(game.world.centerX, game.world.centerY, 1);

    emitter.width = game.world.width;
    emitter.height = game.world.height;

    emitter.setRotation(0, 0);
    emitter.gravity = 0;

    emitter.setYSpeed(-10, 10);
    emitter.setXSpeed(-10, -40);

    emitter.flow(0, 10, 10, -1, true);

Now I'd like to be able to change the particle velocity (the xSpeed and ySpeed of emitter as regarding that specific particle) at one point in the game (for example when the particle reaches the world bounds I want it to gently flow back towards a random point on the screen).

I've tried setting the emitter.setYSpeed and emitter.setXSpeed after I've started it but it doesn't work. Next I'v looked at the particle properties and methods and couldn't find a velocity or force property - sure enough there's a checkWorldBounds property that will launch an event when the particle reaches the world bounds but what am I supposed to do with it if I want to change the particle movement direction?

Then I tried tinkering with forEachAlive function - takes a callback that enumerates over every particle. I've tried various things in the callback function (like setting a tween, modifying x and y directly, randomly create tweens after certain periods of time) but the overall movement looks jaggy/forced/unnatural. 

So anyone have any ideas or should I just roll my own emitter?


Link to comment
Share on other sites


  • Recently Browsing   0 members

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