Flint Particle System Forum - Multiple emitter instances2010-06-13T07:23:30+01:00http://flintparticles.org/forum/
Lussumo Vanilla & Feed Publisher
Multiple emitter instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=459#Comment_4592008-10-30T17:26:09+00:002008-11-04T10:40:35+00:00TheDudehttp://flintparticles.org/forum/account.php?u=87
Why doesn't the following work?
(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 ...
(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 instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=462#Comment_4622008-10-31T12:44:12+00:002010-06-13T07:23:30+01:00Richardhttp://flintparticles.org/forum/account.php?u=1
I just tested your code and it works fine for me - creates a new emitter every time I call the explode function. Perhaps the problem is elsewhere in your code, or the movie clip and the renderer are ...
Multiple emitter instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=467#Comment_4672008-11-01T19:36:17+00:002010-06-13T07:23:30+01:00TheDudehttp://flintparticles.org/forum/account.php?u=87
Yes you were correct. The error was cast by a line I had in my code: Array.prototype.copy=Array.prototype.concat;
Strange huh?
Ok so now that's solved I have another issue. Is there a problem ...
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 instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=468#Comment_4682008-11-03T16:03:39+00:002008-11-03T16:04:09+00:00Richardhttp://flintparticles.org/forum/account.php?u=1
You will need to remove each explosion when you're finished with it - it doesn't stop automatically just ecause you can't see the particles any longer.
When you clean it up, stop the emitter, ...
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...
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 instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=470#Comment_4702008-11-04T00:52:33+00:002008-11-04T10:40:15+00:00TheDudehttp://flintparticles.org/forum/account.php?u=87
After much experimenting I believe this is doing the job well. The FPS always returns to full speed seconds after an explosions.
Notice I couldn't include a stagesize DeathZone as my game scrolls, ...
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 );
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 instanceshttp://flintparticles.org/forum/comments.php?DiscussionID=111&Focus=471#Comment_4712008-11-04T04:42:23+00:002010-06-13T07:23:30+01:00TheDudehttp://flintparticles.org/forum/account.php?u=87
sorry,
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, restart );
should be;
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles );
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, restart );