简体   繁体   English

iPhone游戏开发,使用文件或sqlite保存状态?

[英]iPhone game development, saving state with files or sqlite?

For iphone game development. 用于iPhone游戏开发。 How do most people retain state? 大多数人如何保持状态? Using sqlite? 使用sqlite吗? or some kind of file. 或某种文件。

The game is a RPG type game. 该游戏是RPG类型的游戏。

If you need to search/sort your game data frequently or you typically only load a subset of the data at one time, then you should consider SQLite. 如果您需要经常搜索/排序游戏数据,或者通常一次只加载一部分数据,则应考虑使用SQLite。

If you need to simply store your object graph to disk and reload the whole thing at startup, use NSCoder to archive your game objects to a file (it's stored as a binary plist by default). 如果您只需要将对象图存储到磁盘上并在启动时重新加载整个内容,请使用NSCoder将您的游戏对象存档到文件中(默认情况下,它以二进制plist的形式存储)。

If you need to interchange game data with a server or other system, you might look at a serialization format like XML or JSON. 如果需要与服务器或其他系统交换游戏数据,则可以查看XML或JSON之类的序列化格式。

It really depends on what you want. 这实际上取决于您想要什么。 Both are perfectly acceptable. 两者都是完全可以接受的。 If your game state is really complex, then using a file might be easier (take your game state and encoding it with an NSKeyedArchiver or something). 如果您的游戏状态确实很复杂,那么使用文件可能会更容易(获取您的游戏状态并使用NSKeyedArchiver或其他内容对其进行编码)。 However, if you've got a simple game (the player is on this level at this position), then SQLite would be a great option. 但是,如果您有一个简单的游戏(玩家处于此位置的此级别),那么SQLite将是一个不错的选择。

If you want the best of both worlds, you might also want to consider using CoreData. 如果您希望两全其美,则可能还需要考虑使用CoreData。

For an RPG, you're probably going to need to search through and retrieve elements from a large data set as part of the internal functioning of the game itself, so you should use either SQLite (if targeting OS 2.x) or Core Data (if targeting OS 3.x) for that. 对于RPG,您可能需要在大型数据集中搜索和检索元素,这是游戏本身内部功能的一部分,因此,您应该使用SQLite(如果以OS 2.x为目标)或Core Data。 (如果定位到OS 3.x)。 Because you will be using a database anyway for loading your game assets, it only makes sense to use that for saving state. 因为无论如何您都将使用数据库来加载游戏资产,所以仅将其用于保存状态才有意义。 Again, for an RPG you'll probably be loading and saving a large amount of data for game state, for which a database will be faster than a plain data file. 同样,对于RPG,您可能会加载并保存大量数据以用于游戏状态,为此数据库比普通数据文件要快。

Core Data lets you manage a complex object graph, is faster than even tuned SQLite, can use much less memory, and can be much easier to code, but is only available on iPhone OS 3.x. Core Data使您可以管理复杂的对象图,甚至比调整后的SQLite更快,可以使用更少的内存,并且可以更轻松地编写代码,但是仅在iPhone OS 3.x上可用。 If you still want to target 2.x, SQLite would be the way to go. 如果您仍然希望以2.x为目标,那么SQLite将是您的最佳选择。

In my experience, both Core Data and SQLite have been far faster than plain files for all but the simplest cases requiring data persistence. 以我的经验,除了最简单的需要数据持久性的情况外,对于所有数据,Core Data和SQLite的速度都比普通文件快得多。

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

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