Jump to content

Changing emitter textures


Recommended Posts

I have an emitter which when activated, it will take the texture from what it collided into for its effect animation.  I haven't been able to figure out how to change the texture of the emitter upon the event like I can with a sprite by calling .loadTexture, so I'm currently forced to create a new emitter each time (certainly don't want to be doing this!).


I saw the random sprite.js example for emitters,  but just couldn't figure out how to choose between the options rather than pick from them randomly.


Phaser example:

emitter.makeParticles(['diamond', 'carrot', 'star']);

My code (happens upon a collision event):

ballEmitter = this.game.add.emitter(200, 200 + (i * 16), 5);            ballEmitter.makeParticles(aCombo[0].key);

Thanks ahead of time for any help.  ^_^

Link to comment
Share on other sites

You'll want to be careful with makeParticles, though, as it does exactly that: makes more particles. The existing ones in the emitter are not removed or overwritten, but left as dead.


You might be better off making an emitter per particle sprite you want to use, then calling start on the appropriate one when the collision event happens, adjusting the emitX and emitY values to match where the collision happened.



Emitters themselves do not have textures, they are just Phaser.Groups. They do not store the texture key you pass to makeParticles, they just use them when making the Sprites for the particles. You might be able to get away with

myEmitter.forEach (function(particle){ particle.loadTexture();}, this);

but I haven't tried that at all. The forEach function loops over a Phaser.Groups children - all the particles, in the case of an emitter, - and passes each one to the function you supply.

Link to comment
Share on other sites

  • 3 years later...

to change particle image via makeParticles() method you'll need to restart it, you can see the method, how we done it in our plugin

https://github.com/koreezgames/phaser-particle-editor - this is editor link, here you can create you emitter

https://github.com/koreezgames/phaser-particle-editor-plugin - this is plugin link, here are all emitter specific methods, so you can see how we do that (ES6)

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...