dacatchman Posted April 10, 2015 Share Posted April 10, 2015 Is it possible to get an oncreate callback or some such for the particle emitter? I just want to randomly set the particle color when it's created (via tint, for example). Right now, I have to make a function on update that steps through non-colorized particles and sets a color (then a flag so I don't re-set the color again). This works, but it's not terribly efficient, FPS wise. Any other way to accomplish this? Link to comment Share on other sites More sharing options...
dacatchman Posted April 13, 2015 Author Share Posted April 13, 2015 Anyone? Bueller? Bueller? Link to comment Share on other sites More sharing options...
drhayes Posted April 13, 2015 Share Posted April 13, 2015 I don't know if this is the canonical way to do this... but if you're using a custom particle type you can set these properties at instantiation, right? Link to comment Share on other sites More sharing options...
dacatchman Posted April 21, 2015 Author Share Posted April 21, 2015 Took me a while to followup. For those interested, drhayes was correct. You simply extend Phaser.Particle and there is an onEmit callback that the emitter invokes at creation. Here's some sample code:var confetti_colors = ['FFFF00','FF9933','FF0000','3399FF','9933CC'];var ConfettiParticle = function(game, x, y, key, frame){ Phaser.Particle.call(this, game, x, y, key, frame);}ConfettiParticle.prototype = Object.create(Phaser.Particle.prototype);ConfettiParticle.prototype.constructor = ConfettiParticle;ConfettiParticle.prototype.onEmit = function(){ this.tint = '0x'+confetti_colors[Math.floor(Math.random()*confetti_colors.length)];}... (where you define your emitter) ...emitter.particleClass = ConfettiParticle; Link to comment Share on other sites More sharing options...
drhayes Posted April 22, 2015 Share Posted April 22, 2015 Ah, onEmit is probably the better choice for when the particle gets re-used from a pool. Awesome. Link to comment Share on other sites More sharing options...
Recommended Posts