0

我创建了一个问答游戏,它实现了一个时间栏。第一次玩没问题,但是如果在游戏结束后,玩家点击“重新开始”,游戏可以正常进行,但时间条消失了!

这是我从 GameOverLayer 到 Game 的代码:

-(void) restart {
    [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
}

这里创建一个新问题的功能

-(void)creaDomanda{

    //bar
    CCProgressFromTo *to1 = [CCProgressFromTo actionWithDuration:MaxTime from:100 to:0];
    bar = [CCProgressTimer progressWithFile:@"barra.png"];
    bar.type = kCCProgressTimerTypeHorizontalBarLR;
    [bar setPosition:ccp(size.width - 250 , size.height - 18)];

    int randomValue =  (arc4random() % 4) + 1; 
    NSString *stringa = [NSString stringWithFormat:@"Domanda%i", randomValue];
    dictionary = [plistData objectForKey:stringa];
    domanda = [dictionary valueForKey:@"Titolo"];
    labelDomanda = [CCLabelTTF labelWithString:domanda fontName:@"Marker Felt" fontSize:24];
    labelDomanda.position =  ccp( size.width /2 , 400 );
    [self addChild: labelDomanda];
    int rispostaEsatta = [[dictionary valueForKey:@"Soluzione"] intValue];
    menu = [CCMenu menuWithItems:nil];
    for (int i = 1; i<5;i++)
    {
        if(rispostaEsatta == i){
item = [CCMenuItemFont itemFromString:[dictionary valueForKey:
                                                               [NSString stringWithFormat:@"Risposta%i",i] ]
                                                       target:self selector:@selector(corretto)];
        }else{
            item = [CCMenuItemFont itemFromString:[dictionary valueForKey:
                                                               [NSString stringWithFormat:@"Risposta%i",i] ]
                                                       target:self selector:@selector(sbagliato)];
        }
        [menu addChild:item];
    }
//[..]
    [self addChild:menu];
    [self addChild:bar];
    [bar runAction:to1];
}

毕竟,这里有一个正确/错误的方法(类似),它创建了一个新问题:

-(void)sbagliato{
    CCLOG(@"Sbagliato");

    if (menu) [self removeChild:menu cleanup:YES];
    if (labelDomanda) [self removeChild:labelDomanda cleanup:YES];
    if (bar) [self removeChild:bar cleanup:YES];

    labelRisultato = [CCLabelTTF labelWithString:@"Hai sbagliato!" fontName:@"Marker Felt" fontSize:24];
    [labelRisultato setColor:ccc3(255, 1, 1)];
    labelRisultato.position = ccp(size.width / 2, 280);

    [self addChild:labelRisultato];
    [self gameOver:2 punteggio:0];
    // Richiamiamo il metodo per eliminare la label dopo 0,3 secondi
    [self performSelector:@selector(eliminaLabel) withObject:nil afterDelay:0.5];

    increment = increment - 20;
    [pointLabel setString: [NSString stringWithFormat: @"Punti: %i", increment]];

    // new question
    [self performSelector:@selector(creaDomanda) withObject:nil afterDelay:0.5];
}

谁能向我解释一下为什么当我重新启动时间栏消遣器时?谢谢你

4

1 回答 1

1

我最好的猜测:

CCProgressFromTo 操作仍在运行。由于进度下降到 0,CCProgressTimer 最终不再显示它的任何部分。即使您在进度计时器上运行另一个 CCProgressFromTo 操作,这也可能会继续。

解决方案:确保在运行另一个动作之前停止任何正在运行的 CCProgressFromTo 动作。

如果这不能解决它,那么我想 CCProgressTimer 需要通过将百分比设置回 100 来重置。

于 2013-02-15T14:32:43.683 回答