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

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);	



Link to comment
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;


Link to comment
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?

Link to comment
Share on other sites

  • 2 months later...
  • 4 months later...

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 ? 

Link to comment
Share on other sites


  • Recently Browsing   0 members

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