Jump to content

Custom Emitter, extending Phaser


Recommended Posts



I just started out with Phaser and with GameDev in general. Phaser is awesome, played around with it quite a bit.


I want to make the built in Emitter perform custom operations, so I extended it, and created a new add method to the GameObjectFactory:

Owzim = (typeof Owzim !== 'undefined') ? Owzim : {};Owzim.Emitter = function(game, x, y, particleCount) {		// custom code here		Phaser.Particles.Arcade.Emitter.call(this, game, x, y, particleCount);};Owzim.Emitter.prototype = Object.create(Phaser.Particles.Arcade.Emitter.prototype);Owzim.Emitter.prototype.constructor = Owzim.Emitter;Phaser.GameObjectFactory.prototype.owzimEmitter = function(emitter, x, y, maxParticles) {	return this.game.particles.add(new Owzim.Emitter(this.game, x, y, maxParticles));};

So that I can use it as follows:

emitter = game.add.owzimEmitter(0, 0, 1);

What I essentially want to do is to, make the particles lose in scale and to be killed, when being under a certain value.


But I now I see that it will not be that easy, since the particle logic (velocity, gravity and so on), where I want to put my scale logic is dug elsewhere, in the Body class.


The global update loop seems to be within Physics ... and so on, so there a re multiple parts in which I would have to make changes, or extend things.


What's the best way to achieve that?





Link to comment
Share on other sites

I believe what you want is to set Emitter.particleClass to a custom Sprite class. This should cause the emitter to create particles of that class, which you can define to have whatever behavior you wanted. However, this isn't currently used for some reason (line 320 in Emitter.js is commented out). I was considering submitting a pull request that enabled it, but perhaps Rich has other plans for it... ?

Link to comment
Share on other sites

Thanks for the reply, so how can hook into the global update loop without calling a custom mySpriteObjec.update() method in the update function?

function update() {	myCustomSprites.forEach(function(sprite) {		sprite.update();	});	}

I'd rather want to have the logic encapsulated in the sprite class, and not having to call is from outside.


I can do it with onKill, like so:


Since in the Events Class there is this:

this.onKilled = new Phaser.Signal();

Is see there is an onAnimationLoop event:

this.onAnimationLoop = null;

I don't know if it's what I want, and since it's null I cannot add a custom callback, like so:



Link to comment
Share on other sites


  • Recently Browsing   0 members

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