Flint Particle System Forum - "emitterEmpty" not enough, need "emitterDone" event 2011-12-12T00:48:45+00:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher "emitterEmpty" not enough, need "emitterDone" event http://flintparticles.org/forum/comments.php?DiscussionID=193&Focus=742#Comment_742 2009-04-04T08:30:27+01:00 2009-04-04T08:54:56+01:00 turbidity http://flintparticles.org/forum/account.php?u=179 Problem: I want to create multiple concurrent Emitters that dispatch events when they are done emitting particles. "emitterEmpty" triggers any time an emitter is empty, even if the emitter ... "emitterEmpty" triggers any time an emitter is empty, even if the emitter has a counter that would still produce particles. Useless!

Solution (clumsy hack): I added the "emitterDone" EMITTER_DONE event to the common Emitter class and the EmitterEvent class.
The emitterDone event is triggered when an update happens over 80 times while the emitter is empty.
<code>
// This is a terrible hack in the common Emitter class around line 645:
doneTime++;
dispatchEvent( new EmitterEvent( EmitterEvent.EMITTER_EMPTY ) );
if (doneTime > 80){
dispatchEvent( new EmitterEvent( EmitterEvent.EMITTER_DONE ) );
doneTime = 0;
}
//END
</code>
There is probably a better way of determining when an Emitter is done with it's counter than the above code.


Here is my charge function that creates emitters:
<code>
//
public var renderer:DisplayObjectRenderer=new DisplayObjectRenderer;
addChild(renderer);
//I'm a' chargin my lazor!
public function charge(target:DisplayObject, many:uint = 100, time:Number = 4):void {
var charger:Emitter2D = new Emitter2D;
renderer.addEmitter(charger);
charger.counter = new TimePeriod(many, time, Circular.easeIn);
charger.addInitializer( new ImageClass(Line, 4, 0xFFFFFFFF, "screen") );
charger.addInitializer( new PositionAbsolute(new DiscZone(new Point(target.x, target.y), 50, 20 ) ) );
charger.addInitializer( new Lifetime( 0.5, 1 ) );
charger.addAction( new Age() );
charger.addAction( new Fade() );
charger.addAction( new ColorChange(0xFFDDB6ff, 0xFFFF0000) );
charger.addAction( new Move() );
charger.addAction( new RotateToDirection() );
charger.addAction( new GravityWell( 30, target.x, target.y, 3));
charger.addAction( new DeathZone(new DiscZone(new Point(target.x, target.y), 10 ) ) );
charger.start();
charger.addEventListener("emitterDone", chargeDone);
}

private function chargeDone(e:EmitterEvent):void {
FlashConnect.atrace(e.target);//flash develop trace
e.target.stop();
renderer.removeEmitter(e.target as Emitter);
e.target.removeEventListener("emitterDone", chargeDone);
fireLazor(9000);
}
</code>

Sorry if I've gone about this entirely the wrong way and need to learn more FlintParticle before I post.]]>
"emitterEmpty" not enough, need "emitterDone" event http://flintparticles.org/forum/comments.php?DiscussionID=193&Focus=747#Comment_747 2009-04-06T23:11:31+01:00 2011-12-12T00:48:45+00:00 Richard http://flintparticles.org/forum/account.php?u=1 There is no way for the emitter to directly know whether it is done or not. The only object that knows this is the counter, which knows it's finished emitting all the particles it will emit. This was ... an earlier post but I haven't implemented it yet - pressure of work more than anything else. I will try to add it to the 2.1 release, which I hope to have ready before too long.]]>