Titus Posted October 12, 2017 Share Posted October 12, 2017 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.player.scale.setTo(0.75); this.backArm = this.game.add.sprite(-10, -180, 'backArm'); this.backArm.scale.setTo(0.75); this.frontArm = this.game.add.sprite(-10, -180, 'frontArm'); this.frontArm.scale.setTo(0.75); this.emitter = this.game.add.emitter(0, 0, 5000); this.emitter.makeParticles('whiteParticle'); this.emitter.minParticleSpeed.setTo(200, 0); this.emitter.maxParticleSpeed.setTo(2000, 0); this.emitter.gravity = 200; this.emitter.lifespan = 0; this.playerContainer.addChild(this.backArm); this.playerContainer.addChild(this.player); this.playerContainer.addChild(this.frontArm); this.frontArm.addChild(this.emitter); this.game.physics.arcade.enable(this.playerContainer); this.game.physics.arcade.enable(this.player); this.playerContainer.body.collideWorldBounds = true; this.player.anchor.setTo(0.5); this.frontArm.anchor.setTo(0.4866, 0.2925); this.backArm.anchor.setTo(0.4866, 0.2925); }, Link to comment Share on other sites More sharing options...
samme Posted October 12, 2017 Share Posted October 12, 2017 Usually you don't want to give an emitter a parent because the parent's movement would also move the particles. If you do game.debug.spriteCoords(this.emitter.children[0]); 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; } Makemake Hope and Titus 1 1 Link to comment Share on other sites More sharing options...
Titus Posted October 13, 2017 Author Share Posted October 13, 2017 @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 More sharing options...
GideonSam Posted January 12, 2018 Share Posted January 12, 2018 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) Link to comment Share on other sites More sharing options...
samme Posted January 12, 2018 Share Posted January 12, 2018 The parent sprite must have exists=true and be in the world as well. Link to comment Share on other sites More sharing options...
GideonSam Posted January 13, 2018 Share Posted January 13, 2018 its true and available in the world but its not woking Link to comment Share on other sites More sharing options...
Kiwi404 Posted June 10, 2018 Share Posted June 10, 2018 This bug is always present in 2.10.5 which forces us to come back in <= 2.7.5 Link to comment Share on other sites More sharing options...
Kiwi404 Posted June 10, 2018 Share Posted June 10, 2018 It seems this is not a "bug", but a planned change in Phaser since 2.7.7 to deprecate the update way of particles : https://github.com/photonstorm/phaser-ce/commit/cbe101fee2cdcb7add64e31aa1f289a13f9c8108 https://github.com/photonstorm/phaser-ce/commit/3ea0260777fccd7529e535693a920218a1645cde https://github.com/photonstorm/phaser-ce/commit/3a4c500f96536a27b90b78bb654f370bc0461757 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) { this.emitters[key].update(); } } } and re-append his call in updateLogic in "src/core/Game.js" : this.state.update(); this.stage.update(); this.tweens.update(); this.sound.update(); this.input.update(); this.physics.update(); this.particles.update(); this.plugins.update(); 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 More sharing options...
Recommended Posts