Hi guys,
I am currently writing some code to make a bunch of fairies, each fairy emits "fairy dust’ (particles). These particles are on a timer and are removed after a couple seconds. I am using a dictionary to track the particles.
**My question is this: When I remove the particle from the display list and make it null, will the dictionary automatically shrink (like splicing an array)? I’m worried the dictionary is getting infinitely large since I don’t know how to shrink a dictionary. **
(I tried looking it up, but didn’t find anything helpful)
Here is a snippet of my code:
public function Fairy(...) {
...//other stuff
**particleDict = new Dictionary(true);**
}
private function createParticle():void
{
... //more stuff
var particleTimer:Timer = new Timer(this.parent.stage.frameRate,50);
particleTimer.addEventListener(TimerEvent.TIMER, particleUpdate);
particleTimer.start();
**particleDict[particleTimer] = particle; **
}
private function particleUpdate(e:TimerEvent):void
{
particleDict[e.currentTarget].alpha = 1 - e.currentTarget.currentCount / e.currentTarget.repeatCount;
particleDict[e.currentTarget].y += .5;
if(e.currentTarget.currentCount == e.currentTarget.repeatCount)
{
e.currentTarget.removeEventListener(TimerEvent.TIMER, particleUpdate);
**this.parent.removeChild(particleDict[e.currentTarget]);**
** particleDict[e.currentTarget] = null;**
}
}
Thanks :beer2: