Jump to content

Emitter, remove onComplete


Recommended Posts

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

Link to comment
Share on other sites



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);
Link to comment
Share on other sites

  • 9 months later...

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?


Link to comment
Share on other sites

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.


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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