我正在通过Cocos2d和SpriteBuilder制作游戏。我有问题 :( 。 EX:我的分数第一次是8,高分是8.然后,我重试比赛,我的分数> 8,当我死的时候==>错误显示:(
我的高分数来源:
NSNumber *highScore = [[NSUserDefaults standardUserDefaults] objectForKey:@"_highscore"];
if (self.score > [highScore intValue]) {
// new highscore
highScore = [NSNumber numberWithInt:self.score];
[[NSUserDefaults standardUserDefaults] setObject:highScore forKey:@"_highscore"];--->BUG
[[NSUserDefaults standardUserDefaults] synchronize];
}
答案 0 :(得分:0)
我使用此代码来获取/设置高分。它正在发布的游戏中运行。希望它有所帮助!
+(void)setNewHighScore:(int)score{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:[NSNumber numberWithInt:score] forKey:@"GameNameHighScore"];
}
+(int)getHighScore{
int highScore = 0;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
highScore = [[defaults valueForKey:@"GameNameHighScore"] intValue];
return highScore;
}