2

I'd like to run a callback/selector when a Cocos2d CCParticleExplosion is completely finished. How do I do this?

I tried using scheduleOnce with the same duration as the emitter, but that finish too soon since I guess the duration of the emitter controls for how long it will emit new particles, but not how long the complete animation lasts.

Johan Nordberg
  • 3,621
  • 4
  • 33
  • 58

2 Answers2

0

Try sequencing the action (using CCSequence) with a CCCAllFunc Action. After one action runs, the other runs, the CCCAllFunc can be assigned to the selector/method of your choice.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
0

Not sure if this is acceptable, but I tested and "it works on my mac".

in CCParticleSystem.h

// experimental
typedef void (^onCompletedBlock)();
@property (readwrite, copy) onCompletedBlock onComplete;

in CCParticleSystem.m

@synthesize onComplete;

in the same file update method,

_particleCount--;

        if( _particleCount == 0 && self.onComplete)
        {
            [self onComplete]();
            [[self onComplete] release];
        }

if( _particleCount == 0 && _autoRemoveOnFinish ) {
            [self unscheduleUpdate];
            [_parent removeChild:self cleanup:YES];
            return;
}

In your code

particleSystem.autoRemoveOnFinish = YES;
particleSystem.position = ccp(screenSize.width/2, screenSize.height/4);
particleSystem.onComplete = ^
{
    NSLog(@"completed ..");
};

again, quite experimental..

Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81