Loading Data Files on iPhone?

本秂侑毒 提交于 2019-12-13 04:18:13

问题


What is the best way to load static data files containing game level maps on the iPhone? I have seen some use XML files, but that seems like overkill in my situation as the data files merely determine the layout of the game's level, ie where obstructions will go. Also, what project directory should they be stored in?

Thanks in advance!


回答1:


If your files are really static, then you'll want to store them in your application bundle (just add them to your project; Xcode will copy them to the .app bundle when it builds your application). If you need to modify and re-save them, probably ~/Documents is your best bet.

Marc is correct, an NSDictionary is the simplest way to go, especially for smaller files. If you've got a LOT of data, this could get slow when loading in, but that means 10s, or 100s of kilobytes. Also think about converting your dictionary to binary format when you're happy with its contents, as that will load much faster on the device.




回答2:


I would put the data in a property list file you can load into a dictionary.




回答3:


I would strongly suggest using the existing SQLite functionality that is part of the standard API.

I have found it to be the easiest way to include data during an installation as well as store user generated data.

If you need an example of how to do this check out http://tetontech.wordpress.com/2008/06/28/iphone-objective-c-sqlite-development/



来源:https://stackoverflow.com/questions/317959/loading-data-files-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!