2013-02-15 63 views
0

我創建了一個測驗遊戲,它實現了一個時間條。在第一場比賽中,這是沒問題的,但是如果在比賽結束後,玩家點擊「重新開始」,遊戲會正常進行,但時間欄會消失!重啓遊戲後cocos2d消失的進度時間吧

這裏從GameOverLayer我的代碼遊戲:

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

任何人都可以向我解釋請爲什麼當我重新啓動時間欄d esappers? 謝謝

+0

題外話復位:它的娛樂性閱讀意大利代碼:) – LearnCocos2D 2013-02-15 14:27:20

+0

也是它讓我餓了! :D – LearnCocos2D 2013-02-15 14:33:52

+0

謝謝!我嘗試翻譯一些變量,使代碼更清晰:)但謝謝你:) – TheInterestedOne 2013-02-15 14:52:13

回答

1

我最好的猜測:

的CCProgressFromTo行動仍在運行。由於它進展到0,CCProgressTimer最終不再顯示任何部分。即使您在進度計時器上運行另一個CCProgressFromTo操作,也可能會繼續。

解決方案:確保在運行另一個之前停止正在運行的CCProgressFromTo操作。

如果不解決這個問題,那麼我想象CCProgressTimer需要通過設定比例恢復到100。

+0

我會盡力而且會寫出結果。但爲什麼每次在生成欄中的新問題都會被正確重新初始化,並且在新的重新啓動後,這不會發生? – TheInterestedOne 2013-02-15 14:53:29

+0

對不起,但它並沒有解決它。這可能是因爲每次生成新問題時,該方法都會刪除前一個欄並重新創建一個新欄,重新設置分欄!我不明白爲什麼(newquestion)的所有其他部分都能正常工作,但這部分不一樣! – TheInterestedOne 2013-02-15 15:58:01

+0

沒有什麼可以解決這個問題。我已經解決了與酒吧(殭屍對象)有關的其他問題,但對於這個沒有任何內容。我該如何嘗試調試?爲什麼我的酒吧正常工作,直到我重新開始遊戲? – TheInterestedOne 2013-02-17 18:08:45