Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorturbidity
- CommentTimeApr 4th 2009 edited
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 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. -
- CommentAuthorRichard
- CommentTimeApr 6th 2009
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 discussed in 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.
1 to 2 of 2
