Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone game development, saving state with files or sqlite?

For iphone game development. How do most people retain state? Using sqlite? or some kind of file.

The game is a RPG type game.

like image 838
Berlin Brown Avatar asked Sep 18 '09 18:09

Berlin Brown


3 Answers

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.

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).

If you need to interchange game data with a server or other system, you might look at a serialization format like XML or JSON.

like image 146
Don McCaughey Avatar answered Oct 23 '22 02:10

Don McCaughey


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). However, if you've got a simple game (the player is on this level at this position), then SQLite would be a great option.

If you want the best of both worlds, you might also want to consider using CoreData.

like image 31
Dave DeLong Avatar answered Oct 23 '22 03:10

Dave DeLong


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. 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.

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. If you still want to target 2.x, SQLite would be the way to go.

In my experience, both Core Data and SQLite have been far faster than plain files for all but the simplest cases requiring data persistence.

like image 1
Brad Larson Avatar answered Oct 23 '22 03:10

Brad Larson