简体   繁体   English

在多个情节提要板上使用高分

[英]using high scores on multiple storyboards

I have two storyboards in my game: the home page and the game itself. 我的游戏中有两个故事板:主页和游戏本身。 When a user gets a high score in the game i save it as their high score. 当用户在游戏中获得高分时,我会将其保存为他们的高分。 How can i then take that high score to display it on the homepage without linking the view controllers to the same code. 然后,如何在不将视图控制器链接到相同代码的情况下,将高分显示在主页上。

Save highscore anywhere in your project 将高分保存在项目中的任何位置

[[NSUserDefaults standardUserDefaults] setInteger:score forKey:@"kHighscoreKey"];
[[NSUserDefaults standardUserDefaults] synchronize];

Retrieve highscore anywhere else in your project 检索项目中其他任何地方的高分

NSUInteger highScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"kHighscoreKey"];

If your do not find your score data important or sensitive use NSUserDefaults 如果您认为分数数据不重要或不敏感,请使用NSUserDefaults

First scene: 第一个场景:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:yourHighScore forKey:@"HighScore"];

Second scene: 第二场景:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
yourHighScore = [defaults integerForKey:@"HighScore"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM