inserting time delay with cocos2d

Posted by KDaker on Stack Overflow See other posts from Stack Overflow or by KDaker
Published on 2011-02-16T18:55:50Z Indexed on 2011/02/17 15:25 UTC
Read the original article Hit count: 198

Filed under:
|
|

I am trying to add several labels that appear sequentially with a time delay between each. The labels will display either 0 or 1 and the value is calculated randomly. I am running the following code:

 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]];

    }

the method that makes the labels appear is this:

-(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];
}

The problem with this code is that all the labels appear at the same moment with the same delay. I understand that if i use [CCDelayTime actionWithDuration:0.2*i] the code will work. But the problem is that i might also need to iterate this entire for loop and have the labels appear again after they have appeared the first time. how is it possible to have actions appear with delay and the actions dont always follow the same order or iterations???

© Stack Overflow or respective owner

Related posts about ios

Related posts about cocos2d