Flint Particle System Forum - Multiple emitter instances Sat, 25 Dec 2010 19:04:36 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=459#Comment_459 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=459#Comment_459 Thu, 30 Oct 2008 17:26:09 +0000 TheDude (all the libraries are in place)
What I'm trying to do is create separate instances of emitters every time a spaceship is blown up.

The code will work fine if i put the var emitter and renderer lines outside of the function, but it doesn't create instances every time I call function Explode- it just continues with the one single emitter. Therefore I need some way to instantiate a different emitter each time the function is called. Any ideas?

function Explode(ob:MovieClip)
{
var emitter:Emitter2D = new Emitter2D();

emitter.counter = new Blast( 500 );
//var bitmapData:BitmapData = new Logo(100, 100);
emitter.addInitializer( new SharedImage( new Line( 2 ) ) );

emitter.addInitializer( new Lifetime( 0.2,4 ) );
emitter.addInitializer( new ColorInit( 0xFFFF3300, 0xFFFFFF00 ) );
emitter.addAction( new Age( Quadratic.easeIn) );
emitter.addAction( new Fade( 1.0, 0 ) );
//emitter.addAction( new Accelerate( 0, 10 ) );

//emitter.addAction(new ColorChange(0xffffff00, 0xffdd0000));
emitter.addAction( new Move() );

emitter.addInitializer( new Position( new DiscZone( new Point( ob.x,ob.y ), 40 ) ) );
emitter.addInitializer( new Velocity( new DiscZone( new Point( ob.x,ob.y ), 200, 120 ) ) );

//emitter.addInitializer( new Velocity( new BitmapDataZone( bitmapData, ob.xOrigin, ob.yOrigin ) ) );

emitter.addAction( new Explosion( 8, ob.x, ob.y, 20 ) );

emitter.start( );

var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight ) );

renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.96,0 ] ) );
renderer.addEmitter(emitter );
addChild( renderer );
};
]]>
Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=462#Comment_462 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=462#Comment_462 Fri, 31 Oct 2008 12:44:12 +0000 Richard Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=467#Comment_467 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=467#Comment_467 Sat, 01 Nov 2008 19:36:17 +0000 TheDude
Strange huh?

Ok so now that's solved I have another issue. Is there a problem with the function above in terms of garbage collection? It seriously stalls the fps of my game after just a few explosions. I've a feeling somethings not getting deleted correctly, any ideas?

p.s.love Flint Particle it's been a godsend, keep up the good work- will try to mention it on my blog sometime. ]]>
Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=468#Comment_468 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=468#Comment_468 Mon, 03 Nov 2008 16:03:39 +0000 Richard
When you clean it up, stop the emitter, remove it from the renderer and remove the renderer from the stage. Then null any references you have to the emitter and the renderer. That frees them for the garage collector to clean up. Something like...

emitter.stop();
renderer.removeEmitter( emitter );
removeChild( renderer );
emitter = null;
renderer = null;


If you want to know when to do this. Easiest is probably to place a death zone around the stage, so particles are destroyed when they leave the stage, and then listen for the emitter to send an EMITTER_EMPTY event to indicate it has no particles. When this occurs, do the clean-up as described above.

Alternatively, it might be more efficient to use the same renderer for all emitters. In which case to clean up the emitter you just stop the emitter, remove it from the renderer and null the reference to it. ]]>
Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=470#Comment_470 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=470#Comment_470 Tue, 04 Nov 2008 00:52:33 +0000 TheDude Notice I couldn't include a stagesize DeathZone as my game scrolls, but others might want to think about it.

var renderer:PixelRenderer ;
function Explode(ob:MovieClip, vx, vy)
{

renderer = new PixelRenderer( new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight ) );
//Add whatever filters you need for the renderer here.
var bb:BlurFilter = new BlurFilter( 2, 2, 1 );
renderer.addFilter(bb);
renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.96,0 ] ) );
addChild( renderer );

var emitter:Emitter2D = new Emitter2D();

//Emitter actions and filters go here

renderer.addEmitter(emitter );

emitter.start( );

//GARBAGE DISPOSAL
emitter.addEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles );

};

function kill_particles( ev:EmitterEvent ):void
{
ev.target.stop();
renderer.removeEmitter( Emitter2D( ev.target ) );
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, restart );

ev = null;
removeChild(renderer);
renderer = null;
}


Thanks Richard for the great particle system. I'll be sure to mention it on my blog next post. ]]>
Multiple emitter instances http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=471#Comment_471 http://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=471#Comment_471 Tue, 04 Nov 2008 04:42:23 +0000 TheDude
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, restart );

should be;

ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles ); ]]>