我试着更好地解释这种情况。
这些变量包括:
int punteggio;
CCLabelTTF *labelPunteggio;然后在init metod中,我在屏幕上打印我的分数:
- (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;
}
}谢谢!
发布于 2013-03-09 00:48:57
使用NSUserdefaults
// Snippet used to save your highscore in the prefs.
int highScore = yourGameScore;
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highScore] forKey:@"HighScore"];
[[NSUserDefaults standardUserDefaults] synchronize];//在游戏中翻屏
// Get your highscore from the prefs.
highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"HighScore"] intValue ];发布于 2013-03-09 05:05:32
看看这个link,您可以使用SettingManager类来为您完成这项工作。我使用了settingManager类来存储高分。希望这能有所帮助
https://stackoverflow.com/questions/15298538
复制相似问题