Jump to content

Set Particle Property At Creation


dacatchman
 Share

Recommended Posts

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

  • 2 weeks later...

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

 Share

  • Recently Browsing   0 members

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