1

I am trying to add a particle trail effect in cocos2d, I managed to do it by adding CCParticleSystemQuad emitter as a child to the moving sprite. But I am observing that this emitter is not getting deallocated eventually.

if I add this emitter to same sprite, but keep it still and dont move at all, emitter does get deallocated.

I cant figure out why this is happening..

code is somewhat like this..

CCParticleSystemQuad *emitter = [[[CCParticleSystemQuad alloc] initWithFile:@"myEffect.plist"] autorelease];
emitter.positionType = kCCPositionTypeFree;
emitter.autoRemoveOnFinish = YES;
[movingSprite addChild:emitter z:movingSprite.zOrder + 1000];
imagin
  • 317
  • 3
  • 13

1 Answers1

2

Make sure you called [emitter removeFromParentAndCleanup:YES];

Here is one of my similar question

Find out where object is retained, follow Morion's answer in above thread.

Quick Solution:

CCParticleSystemQuad *emitter = [CCParticleSystemQuad particleWithFile:@"myEffect.plist"];
emitter.positionType = kCCPositionTypeFree;
emitter.autoRemoveOnFinish = YES;
[movingSprite addChild:emitter z:movingSprite.zOrder + 1000];

//To remove
[emitter stopSystem];
[emitter removeFromParentAndCleanup:YES];
Community
  • 1
  • 1
Guru
  • 21,652
  • 10
  • 63
  • 102
  • 1
    The reason why this was happening was that I was calling [movingSprite removeFromParentAndCleanup:NO] when I was done moving, but the duration of emitter was longer than that, so emitter's action wasn't removed and hence it wasn't deallocated. I should either call [movingSprite removeFromParentAndCleanup:YES] or do the above.. thanks it is clear to me now. – imagin Apr 20 '13 at 05:05