attach an emitter as child of sprite

Recommended Posts

Hi Guys,

I'm having some issues with an emitter that I am trying to attach to a sprite using the addChild method. The emitter should be a child of the player's arm so that it moves and rotates correctly. When I add the emitter to the game without being added as a child it works fine. As soon as I add it as a child to the arm it disappears from the game world. I've played around with a bunch of different coordinates  in case it was being moved slightly off screen but I've come to the conclusion that something is going wrong here. I've also run tests in a new state with just a single sprite and an emitter and as soon as I add the emitter asChild of the sprite it is gone. I'm probably missing the thing that is going wrong here, so any help would be appreciated. I'll put my code snippet below if that helps at all


create: function() {

		this.game.stage.backgroundColor = "#000";


		this.playerContainer = this.game.add.sprite(300, 600, null);
		this.player = this.game.add.sprite(0, 0, 'player');	
		this.backArm = this.game.add.sprite(-10, -180, 'backArm');	
		this.frontArm = this.game.add.sprite(-10, -180, 'frontArm');

		this.emitter = this.game.add.emitter(0, 0, 5000);
		this.emitter.minParticleSpeed.setTo(200, 0);
        this.emitter.maxParticleSpeed.setTo(2000, 0);
        this.emitter.gravity = 200;
        this.emitter.lifespan = 0;



		this.playerContainer.body.collideWorldBounds = true;
		this.frontArm.anchor.setTo(0.4866, 0.2925);	
		this.backArm.anchor.setTo(0.4866, 0.2925);	



Share this post

Link to post
Share on other sites

Usually you don't want to give an emitter a parent because the parent's movement would also move the particles. If you do


you may be able to find where it went.

Try instead something like

function update () {
    this.emitter.emitX = this.frontArm.world.x;
    this.emitter.emitY = this.frontArm.world.y;


Share this post

Link to post
Share on other sites

@samme Thanks you. That was very helpful. I had tried using the update function to attach the emitter to another sprite but I was using this.emitter.x instead of this.emitter.emitX and it didn't work.

Interestingly when debugging the emitter (I had to use children[1] to get any debug info) I get coordinates of the first particle when it is not a child. As soon as I add it as a child of a sprite there is no debug information. Do you think there could be a bug in the current version of phaser?

Share this post

Link to post
Share on other sites

Did you find any solution, Once i add the emitter to the sprite it stops emitting i consoled  it and the count remains 0,

If its added to the game it works fine.

The above issue was not working from v2.7.6  (working fine till 2.7.5)

Share this post

Link to post
Share on other sites

It seems this is not a "bug", but a planned change in Phaser since 2.7.7 to deprecate the update way of particles :


I was able to make it work again ( emitter as child ) in the last build 2.10.6 by bringing back deleted "update" method of "src/particles/Particles.js" :

    update: function () {
        for (var key in this.emitters)
            if (this.emitters[key].exists)


and re-append his call in updateLogic in "src/core/Game.js" :


But i think that if they were deprecated it's for a good reason, @samme can you explain us how to get children emitters work in the 'normal' new way ? 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.