Phempt Posted November 2, 2014 Share Posted November 2, 2014 Hello guys, I noticed that creating a lot of emitter, the FPS counter is decreased from 59 to 30. Is there a way to remove each emitter after the animation? Something like "onComplete" for animation. Thank you =) Quote Link to comment Share on other sites More sharing options...
Stephan Posted November 2, 2014 Share Posted November 2, 2014 I guess you can use the emitter.remove() function to remove it from the Emitter array in main.Scene. (http://www.pandajs.net/docs/classes/game.Emitter.html#method_remove)If you remove all other references as well, the emitter will be removed automatically in javascript. If you are using a lot of emitters, perhaps pooling is a better alternative. Have a look at the link in the post http://www.html5gamedevs.com/topic/10014-object-pool-in-panda/.I don't know your exact code but my guess is that not the emitter itself but the particles are decreasing your fps. (The emitter itself is very leight weighted). Hope this is helpful Quote Link to comment Share on other sites More sharing options...
enpu Posted November 3, 2014 Share Posted November 3, 2014 Hey, I have just added onComplete function to Emitter, example:var emitter = new game.Emitter();emitter.textures.push('particle.png');emitter.position.set(100, 100);emitter.duration = 1000;emitter.onComplete(function() { // Emitter complete});emitter.addTo(game.scene.stage);game.scene.addEmitter(emitter); Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 3, 2014 Author Share Posted November 3, 2014 @Stephan when the player touch the right enemy an emitter spawn stars, so it's possible that the final count of emitter spawned is huge. @enpu: that's great! I can add this:emitter.onComplete(function() {this.remove();});to solve my problems ^^ Quote Link to comment Share on other sites More sharing options...
zakhov Posted August 17, 2015 Share Posted August 17, 2015 I've tried this as well but keep getting Uncaught TypeError: this.emitter.onComplete is not a function. this.emitter = new game.Emitter(); this.emitter.textures.push('particle'); this.emitter.angleVar = 50; this.emitter.rate = 10; this.emitter.count = 5; this.emitter.duration = 100; this.emitter.endAlpha = 0; this.emitter.speedVar = 50; this.emitter.startPos.set(300,300); this.emitter.addTo(game.scene.objectContainer); game.scene.addEmitter(this.emitter); this.emitter.onComplete(function() { // Emitter complete this.remove(); }); I'm using the latest PandaJS dev version(2.0), has there been any changes in how the function is called?Thanks Quote Link to comment Share on other sites More sharing options...
enpu Posted August 17, 2015 Share Posted August 17, 2015 trythis.emitter.onComplete = function() { this.remove();}; zakhov 1 Quote Link to comment Share on other sites More sharing options...
zakhov Posted August 17, 2015 Share Posted August 17, 2015 Cheers enpu, the code returned no errors and successfully posted a console log that I put to test. But the emitter count still stays and doesn't reduce in the debug. I'm triggering the emitter on an object collision as shown below: collide: function() { this.emitter = new game.Emitter(); this.emitter.textures.push('particle'); this.emitter.angleVar = 120; this.emitter.rate = 60; this.emitter.count = 40; this.emitter.duration = 300; this.emitter.endAlpha = 0; this.emitter.speedVar = 50; this.emitter.startPos.set(this.sprite.position.x + 60, this.sprite.position.y + 70); this.emitter.onComplete = function() { this.remove(); console.log('test remove emitter'); }; this.emitter.addTo(game.scene.objectContainer); game.scene.addEmitter(this.emitter); },Basically I want a particle effect on a collision between two objects, sort of like bullet debris when it hits the wall.Right now it works fine and is showing the effect I want. But I'm still a bit annoyed that the emitter count isn't reducing after completion.It's not affecting performance or the game in any way though, I'm just curious whether the way I'm coding it is the cause.Thanks Quote Link to comment Share on other sites More sharing options...
enpu Posted August 17, 2015 Share Posted August 17, 2015 That seems to be a bug with Panda 2. I just pushed update, can you test if it works now? Thanks! Quote Link to comment Share on other sites More sharing options...
zakhov Posted August 18, 2015 Share Posted August 18, 2015 Hi enpu, using the same code as above with the latest update freezes the game and triggers an infinite error log in the console - this.parent is not a functionI'm not sure exactly but I think the "this.remove();" function might be the culprit. Quote Link to comment Share on other sites More sharing options...
enpu Posted August 18, 2015 Share Posted August 18, 2015 Sorry my bad! Can you try now again? zakhov 1 Quote Link to comment Share on other sites More sharing options...
zakhov Posted August 18, 2015 Share Posted August 18, 2015 Sorry my bad! Can you try now again? That solved it! Cheers enpu! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.