我創建了一個測驗遊戲,它實現了一個時間條。在第一場比賽中,這是沒問題的,但是如果在比賽結束後,玩家點擊「重新開始」,遊戲會正常進行,但時間欄會消失!重啓遊戲後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? 謝謝
題外話復位:它的娛樂性閱讀意大利代碼:) – LearnCocos2D 2013-02-15 14:27:20
也是它讓我餓了! :D – LearnCocos2D 2013-02-15 14:33:52
謝謝!我嘗試翻譯一些變量,使代碼更清晰:)但謝謝你:) – TheInterestedOne 2013-02-15 14:52:13