save and load highscore

后端 未结 1 1723
执念已碎
执念已碎 2020-12-18 09:29

i tried to use NSUserDefults to save and load a highscore(nsinteger) for my game. i created an void function that check if the gameoverscore is bigger than my highscore and

相关标签:
1条回答
  • 2020-12-18 09:52
    // Snippet used to save your highscore in the prefs.
    int highScore  = yourGameScore;
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highScore] forKey:@"HighScore"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    
    // Snippet used to get your highscore from the prefs.
    highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"HighScore"] intValue ];
    
    0 讨论(0)
提交回复
热议问题