gpt4 book ai didi

ios - 用cocos2d插入时间延迟

转载 作者:可可西里 更新时间:2023-11-01 04:10:24 27 4
gpt4 key购买 nike

我正在尝试添加几个按顺序出现的标签,每个标签之间有时间延迟。标签将显示 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]];

}

让标 checkout 现的方法是这样的:

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

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

最佳答案

可能我不是很明白你想做什么。但是,如果您在标 checkout 现时需要一些控制(以迭代某些内容),请执行以下操作:

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

}

关于ios - 用cocos2d插入时间延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5020796/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com