用cocos2d插入时间延迟

KDa*_*ker 5 cocos2d-iphone ios

我试图添加几个顺序出现的标签,每个标签之间有一个时间延迟.标签将显示0或1,并且值是随机计算的.我正在运行以下代码:

 for (int i = 0; i < 6; i++) {

        NSString *cowryString;
        int prob = arc4random()%10;

        if (prob > 4) {
            count++;
            cowryString = @"1";
        }
        else {

            cowryString = @"0";
        }


        [self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:0.2] ,[CCCallFuncND actionWithTarget:self selector:@selector(cowryAppearWithString:data:) data:cowryString], nil]];

    }
Run Code Online (Sandbox Code Playgroud)

使标签出现的方法是:

-(void)cowryAppearWithString:(id)sender data:(NSString *)string {

CCLabelTTF *clabel = [CCLabelTTF labelWithString:string fontName:@"arial" fontSize:70];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
clabel.position = ccp(200.0+([cowries count]*50),screenSize.height/2);
id fadeIn = [CCFadeIn actionWithDuration:0.5];
[clabel runAction:fadeIn];
[cowries addObject:clabel];
[self addChild:clabel];
}
Run Code Online (Sandbox Code Playgroud)

此代码的问题在于所有标签在相同时刻出现并具有相同的延迟.我明白,如果我使用[CCDelayTime actionWithDuration:0.2*i]代码将工作.但问题是我可能还需要迭代整个for循环并让标签在第一次出现后再次出现.怎么可能有动作出现延迟和动作不总是遵循相同的顺序或迭代?

And*_*rew 14

也许我真的不明白你想做什么.但是,如果你需要一些控制标签出现(迭代某些东西),可以这样做:

-(void) callback
{
    static int counter = 0;
    //create your label and label action here
    // iterate through your labels if required
    counter++;

    if (counter < 6)
    {
        double time = 0.2;
        id delay = [CCDelayTime actionWithDuration: time];
        id callbackAction = [CCCallFunc actionWithTarget: self selector: @selector(callback)];
        id sequence = [CCSequence actions: delay, callbackAction, nil];
        [self runAction: sequence];
    }
    else
    {
    //calculate the result and run callback again if required
    //don't forget to write counter = 0; if you want to make a new throw
    }

}
Run Code Online (Sandbox Code Playgroud)