Yora Posted December 5, 2013 Share Posted December 5, 2013 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 More sharing options...
LuckieLordie Posted December 6, 2013 Share Posted December 6, 2013 this.smokeEmitter.makeParticles('smoke'); This changes the texture you want to use That was taken from some of my code, the makeParticles function is what you want though. Link to comment Share on other sites More sharing options...
XekeDeath Posted December 9, 2013 Share Posted December 9, 2013 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 withmyEmitter.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. shawnbless 1 Link to comment Share on other sites More sharing options...
Yora Posted December 11, 2013 Author Share Posted December 11, 2013 The forEach method worked out like you thought it would. Thanks a bunch, I wouldn't have figured it out on my own. Link to comment Share on other sites More sharing options...
RollinSafary Posted October 27, 2017 Share Posted October 27, 2017 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 More sharing options...
Recommended Posts