精灵套装保存最高分 [英] sprite Kit save highest score

查看:107
本文介绍了精灵套装保存最高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Sprite Kit(使用swift xCode 6 beta 4)构建游戏,我需要保持玩家达到的最高分(所以只有一个Int)。我知道有一种方法可以使用NSCoding来实现,我用谷歌搜索它并找到了我不能使用的Objective-C教程/指南,因为我根本不了解objective-c,也许有更好的方法来了在xCode的后期版本中。任何帮助将不胜感激!

I build a game using Sprite Kit(with swift xCode 6 beta 4) and I need to keep the highest score that the player reached(so just an one Int). I know there is a way to do it using NSCoding, I googled it and found only Objective-C tutorials/guides which I can't use because I don't know objective-c at all, and maybe there are better ways that came in late versions of xCode. Any help will be appreciated!

推荐答案

您可以在 NSUserDefaults 。它用于保存少量数据并且非常易于使用。您可以保存最高分,例如

You can save the highest score in NSUserDefaults. It is used to persist small amount of data and really easy to use.You can save the highest score like

// To save highest score
var highestScore:Int = 20
NSUserDefaults.standardUserDefaults().setObject(highestScore, forKey:"HighestScore")
NSUserDefaults.standardUserDefaults().synchronize()

// To get the saved score
var savedScore: Int = NSUserDefaults.standardUserDefaults().objectForKey("HighestScore") as Int
println(savedScore)

NSUserDefaults 主要用于持久保存这类数据,如高分用户。

NSUserDefaults is mainly used for persisting these kind of data like high-score of user.

这篇关于精灵套装保存最高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆