Flint Particle System Forum - Automatic Clean Up Sun, 11 Dec 2011 06:09:58 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1288#Comment_1288 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1288#Comment_1288 Mon, 09 Aug 2010 16:13:19 +0100 NickyD This works fine assuming the player/user does not grab a second power up before the timer is up and the previous effect is cleaned. Is there an action or way to tell an emitter to clean itself up on its own when the last particle dies?

//START SNIPPET**************************************************

public var trail:Emitter2D;
public var trailRenderer:BitmapRenderer;
private var killTimer:Timer;

//CLEANS UP THE HEART EFFECT FROM STAGE AND MEMORY********************************************************************
//@xPos -the x position in which to draw the effect to
//@yPos -the y position in which to draw the effect to
public function GetHeart(xPos:Number, yPos:Number):void
{
var _xPos:Number = xPos + 2;
var _yPos:Number = yPos + 10;

trail = new Emitter2D();
trail.counter = new TimePeriod(15, 0.4);
trail.addInitializer(new SharedImage(new Dot(6)));
trail.addInitializer(new ColorInit(0xFF9999, 0xFFCCFFCC));
trail.addInitializer(new Position(new DiscZone(new Point(_xPos, _yPos), 15)));
trail.addAction(new DeathZone(new DiscZone(new Point(_xPos, _yPos), 180), true));
trail.addInitializer(new Lifetime(1.8,2.6));

trail.addAction(new Age(Quadratic.easeInOut));
trail.addAction(new Move());
trail.addAction(new Fade(0, 1));
trail.addAction(new Jet(12, -45, new RectangleZone(_xPos - 200, _yPos - 200, _xPos + 200, _yPos + 200),false));
trail.addAction(new RandomDrift(150, 150));
trail.addAction(new LinearDrag(0.3));
trail.addAction(new ColorChange(0xFF0000, 0x00CCFFCC));
trail.addAction(new ScaleAll(1, 0));

trailRenderer = new BitmapRenderer(new Rectangle(_xPos - 200, _yPos - 200, _xPos + 200, _yPos + 200));
trailRenderer.addFilter(new BlurFilter(8, 8, 2));
trailRenderer.addFilter(new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0]));
trailRenderer.addEmitter(trail);

addChild(trailRenderer);
trail.start();

killTimer = new Timer(2600);
killTimer.addEventListener(TimerEvent.TIMER, CleanGetHeart);
killTimer.start();
}

//CLEANS UP THE HEART EFFECT FROM STAGE AND MEMORY********************************************************************
public function CleanGetHeart(evt:TimerEvent):void
{
killTimer.stop();
killTimer.removeEventListener(TimerEvent.TIMER, CleanGetHeart);
killTimer = null;

trail.stop();
ParticleCreator2D(trail.particleFactory).clearAllParticles();
trailRenderer.removeEmitter(trail);
trail = null;
removeChild(trailRenderer);
trailRenderer = null;
}

//END SNIPPET ************************************************************

Help is much appreciated. Thank you! ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1289#Comment_1289 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1289#Comment_1289 Mon, 09 Aug 2010 17:04:52 +0100 NickyD
//ADDS THE OBTAIN HEART EFFECT TO THE STAGE AND MEMORY********************************************************************
//@xPos -the x position in which to draw the effect to
//@yPos -the y position in which to draw the effect to
private function GetHeartEffect(xPos:Number, yPos:Number):void
{
var _xPos:Number = xPos + 2;
var _yPos:Number = yPos + 10;

trail = new Emitter2D();
trail.counter = new TimePeriod(15, 0.4);
trail.addInitializer(new SharedImage(new Dot(6)));
trail.addInitializer(new ColorInit(0xFF9999, 0xFFCCFFCC));
trail.addInitializer(new Position(new DiscZone(new Point(_xPos, _yPos), 15)));
trail.addAction(new DeathZone(new DiscZone(new Point(_xPos, _yPos), 180), true));
trail.addInitializer(new Lifetime(1.8,2.6));

trail.addAction(new Age(Quadratic.easeInOut));
trail.addAction(new Move());
trail.addAction(new Fade(0, 1));
trail.addAction(new Jet(12, -45, new RectangleZone(_xPos - 200, _yPos - 200, _xPos + 200, _yPos + 200),false));
trail.addAction(new RandomDrift(150, 150));
trail.addAction(new LinearDrag(0.3));
trail.addAction(new ColorChange(0xFF0000, 0x00CCFFCC));
trail.addAction(new ScaleAll(1, 0));

trail.addEventListener(EmitterEvent.EMITTER_EMPTY, CleanEmitter);

trailRenderer = new BitmapRenderer(new Rectangle(_xPos - 200, _yPos - 200, _xPos + 200, _yPos + 200));
trailRenderer.addFilter(new BlurFilter(8, 8, 2));
trailRenderer.addFilter(new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.95,0]));
trailRenderer.addEmitter(trail);

addChild(trailRenderer);
trail.start();
}

//CLEANS UP THE HEART EFFECT FROM STAGE AND MEMORY********************************************************************
private function CleanEmitter(evt:EmitterEvent):void
{
trail.removeEventListener(EmitterEvent.EMITTER_EMPTY, cleanEmitter);
trail.stop();
ParticleCreator2D(trail.particleFactory).clearAllParticles();
trailRenderer.removeEmitter(trail);
trail = null;
removeChild(trailRenderer);
trailRenderer = null;
} ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1290#Comment_1290 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1290#Comment_1290 Tue, 10 Aug 2010 08:25:43 +0100 Richard
I see no way to automate the clean-up within Flint since a key part of the clean-up is setting your references to the emitter and renderer to null.

The call to clearAllParticles is unrelated to the rest of the code, and possibly not desired. The particleFactory retains dead particles so they can be reused in other effects later. This makes the initializing of those effects slightly quicker because the particles don't need to be created.

Aside from that, your code is much like I would write. ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1292#Comment_1292 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1292#Comment_1292 Wed, 11 Aug 2010 17:50:18 +0100 NickyD Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1337#Comment_1337 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1337#Comment_1337 Mon, 13 Sep 2010 08:59:13 +0100 Xor I see no way to automate the clean-up within Flint since a key part of the clean-up is setting your references to the emitter and renderer to null.

You don't need to keep a reference and then it's possible to let the effect clean itself up. I use this in a simple effect framework that is instantiated, added to the display list and then removes itself from the list once some conditions are met. Since the display list will retain the object it will live until it removes itself. At that point there are no more references and the garbage collection can take care of it.

Of course, if you want to still interact with the effect you'll need to keep a reference and null it when it's time to let it go. ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1352#Comment_1352 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1352#Comment_1352 Thu, 16 Sep 2010 08:12:02 +0100 Richard Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1562#Comment_1562 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1562#Comment_1562 Sat, 26 Feb 2011 19:06:04 +0000 killerspaz
I'm playing with a fun environment where the user can click on the renderer, and explosions occur. There could be as many explosions as the user desires at any given time.

My approach is to create a new emitter per click, position it based on mouse coords, and start it up.
My issue is that i have a BlurFilter applied to the renderer (BitmapRenderer), and upon an EMITTER_EMPTY, i still have artifacts from a blurred emitter on the renderer.

I can't for the life of me figure out a good way to clean this up!

I don't want to remove the filter or do anything drastic, as the user can start another emitter up around the time a pre-existing emitter is expiring. But if the emitter is stopped or removed, it seems the renderer stops executing filters.

If i don't remove the emitter, clearly performance drops quickly as the pre-existing emitters are constantly dispatching that they're empty. I am going to move it to a pooled emitter system, but with just a single emitter active, this doesn't solve the issue.

Any help? ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1563#Comment_1563 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1563#Comment_1563 Sun, 27 Feb 2011 00:56:53 +0000 killerspaz
Since my situation doesn't really have a lot of overhead, and isn't a game - I found it useful to have the renderer executing non stop.

The way I did this was adding a bogus emitter:

//Add a bogus emitter to force renderer to continue working.
var bogusEmitter:Emitter = new Emitter();
bogusEmitter.counter = new ZeroCounter();
bogusEmitter.start();
this._renderer.addEmitter(bogusEmitter);

This way the renderer is still listening for Event.RENDER because it still has an emitter in it. This emitter just happens to do nothing. I suppose this is akin to say a game loop, I want the "game" engine to run forever.. In my case, it's just a BlurFilter on the renderer.

Now while this satisfies my situation, I'm curious what the more appropriate approach would be for say someone doing a game where an explosion might occur, and blurring is utilized for effect. Would they just do something (which i was trying to avoid) cheezy and just say "ok after 5 seconds finally remove the emitter?" I wanted something a bit more accurate, but the ONLY thing I could think of was analyzing pixel data in the bitmap, which i would assume to be pretty slow in between each filter apply. And even still, that'd be more logic I'd have to write that I just don't care to do right now. ]]>
Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1568#Comment_1568 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1568#Comment_1568 Sun, 27 Feb 2011 13:34:38 +0000 Richard Automatic Clean Up http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1570#Comment_1570 http://flintparticles.org/forum/comments.php?DiscussionID=381&Focus=1570#Comment_1570 Sun, 27 Feb 2011 21:35:25 +0000 killerspaz