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.

4

2 回答 2

0

尝试使用操作对操作进行排序(使用 CCSequence)CCCAllFunc。在一个动作运行后,另一个动作运行后,CCCAllFunc 可以分配给您选择的选择器/方法。

于 2012-04-21T10:07:49.363 回答
0

不确定这是否可以接受,但我测试并“它适用于我的 Mac”。

在 CCParticleSystem.h

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

在 CCParticleSystem.m 中

@synthesize onComplete;

在相同的文件更新方法中,

_particleCount--;

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

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

在您的代码中

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

再次,相当实验性..

于 2013-06-20T03:43:07.393 回答