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

そして、ここでは、最終的に新しい質問を作成する正しい/間違った方法(同様)の1つ:

-(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 アクションを必ず停止してください。

それでも問題が解決しない場合は、パーセンテージを 100 に戻して CCProgressTimer をリセットする必要があると思います。

于 2013-02-15T14:32:43.683 に答える