我試圖解釋更好的情況。保存高分cocos2d
的變量是:
int punteggio;
CCLabelTTF *labelPunteggio;
然後在init梅託德打印我的成績在屏幕上:
- (id)init {
if ((self = [super init])) {
// PUNTEGGIO
labelPunteggio = [CCLabelTTF labelWithString:@"0000" fontName:@"Marker Felt" fontSize:13];
[self addChild:labelPunteggio];
....
}
}
這是添加在Punteggio得分的功能:例如,每時間我殺了一個怪物,我加了10分。
-(void)aggiungiPunti
{
punteggio = punteggio +0001;
[labelPunteggio setString:[NSString stringWithFormat:@"%d", punteggio]];
}
但現在,我不知道當玩家做遊戲時如何保存分數。 我願意保存這個分數,然後打印高分屏幕上, 我想
-(void) setScore:(int)score
{
punteggio = highScore;
if (punteggio>highScore)
{
highScore = punteggio;
}
}
謝謝!
xcode給我的錯誤...我不知道爲什麼.. – 2013-03-08 19:43:09
哪個錯誤?名稱 – Guru 2013-03-09 04:50:04
錯誤是:行[[NSUserDefaults standardUserDefaults] synchronize]上的預期「]」; – 2013-03-09 19:03:44