Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorTheDude
- CommentTimeOct 30th 2008 edited
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 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 );
}; -
- CommentAuthorRichard
- CommentTimeOct 31st 2008
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 not in the same coordinate space. Sorry I can't help more. -
- CommentAuthorTheDude
- CommentTimeNov 1st 2008
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 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. -
- CommentAuthorRichard
- CommentTimeNov 3rd 2008 edited
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, 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. -
- CommentAuthorTheDude
- CommentTimeNov 4th 2008 edited
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, 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. -
- CommentAuthorTheDude
- CommentTimeNov 4th 2008
sorry,
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, restart );
should be;
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles );
1 to 6 of 6
