totallybueno Posted January 27, 2016 Share Posted January 27, 2016 Hi there, I have a problem with an emitter, I´m making a shoot´em up and one of the weapons I have is something like a circular explosion (see the picture), shooting 20 bullets but the game get slower and slower, so I check the emitter and instead of 20 bullets it seems is shooting 1050 each time I use it. Also, everytime I shoot I´m adding 1050 bullets instead of reusing them, so I guess I should use something else instead of start() I´m always having problems with the emitter, it seems that I don´t understand them really well (is even worse with the Particle Storm plugin!)... so, can anyone tell me why the hell is happening this? I have no idea... if(!this.myEmitter){ this.myEmitter = this.game.add.emitter(); var EXPLODE_DIAMETER = 20.0; this.myEmitter.x = this.mySprite.x - EXPLODE_DIAMETER/2; this.myEmitter.y = this.mySprite.y - EXPLODE_DIAMETER/2; for (var i = 0; i <= 360; i=i+18) { var xsp = Math.cos(2 * Math.PI * i / 360.0) * EXPLODE_DIAMETER * 20; this.myEmitter.setXSpeed(xsp, xsp); var ysp = Math.sin(2 * Math.PI * i / 360.0) * EXPLODE_DIAMETER * 20; this.myEmitter.setYSpeed(ysp, ysp); this.myEmitter.gravity = 0; this.myEmitter.minParticleScale = 0.5; this.myEmitter.maxParticleScale = 0.5; this.myEmitter.start(true, 2000, null, 1); this.myEmitter.makeParticles("bullet"); this.myEmitter.update(); } } console.log(this.myEmitter.children.length)//IT ADDS 1050 evertime I .start() the emitter Link to comment Share on other sites More sharing options...
totallybueno Posted January 27, 2016 Author Share Posted January 27, 2016 Ok, so I just readed in the docs that makeParticles() generates a new set of particles and that was why I was adding and adding more and more bullets to the game... Anyway, does anyone know why I´m shooting 1050 bullets instead of 20 (360 degrees / 18 iterations in the for loop)? Link to comment Share on other sites More sharing options...
drhayes Posted January 27, 2016 Share Posted January 27, 2016 The default number of particles in an emitter is 50. You've got an off-by-one error in your loop (double-counting 0 and 360), so there's 21 iterations. 21 * 50 = 1050. totallybueno 1 Link to comment Share on other sites More sharing options...
totallybueno Posted January 27, 2016 Author Share Posted January 27, 2016 3 minutes ago, drhayes said: The default number of particles in an emitter is 50. You've got an off-by-one error in your loop (double-counting 0 and 360), so there's 21 iterations. 21 * 50 = 1050. Oh, ok, now I know that... but anyway, why is releasing 50 particles if I´m telling it just to relase one in the fourth parameter of the start() method? Link to comment Share on other sites More sharing options...
drhayes Posted January 27, 2016 Share Posted January 27, 2016 The first parameter to start is "explode". By setting it to true, you're telling it to release all its particles, regardless of the fourth parameter's value. totallybueno 1 Link to comment Share on other sites More sharing options...
totallybueno Posted January 27, 2016 Author Share Posted January 27, 2016 Oh, ok, so I fixed that with a maxParticles... but still pretty weird, I´m seeing 21 bullets on the screen and the console.log returns 441. And thanks a lot by the way Link to comment Share on other sites More sharing options...
drhayes Posted January 27, 2016 Share Posted January 27, 2016 Which console.log? It's not in that first code snippet. Although, if it helps, 441 is 21*21. Link to comment Share on other sites More sharing options...
totallybueno Posted January 28, 2016 Author Share Posted January 28, 2016 Yep, there´s a console.log at the end... anyway, I saw that if I change the emitter.maxParticles to 1 I´m shooting just those 21 bullets, still not understanding what the hell is happening but at least is working Thanks for your help dude. Link to comment Share on other sites More sharing options...
Recommended Posts