在iPhone上加载数据文件? [英] Loading Data Files on iPhone?

查看:169
本文介绍了在iPhone上加载数据文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone上加载包含游戏级别地图的静态数据文件的最佳方式是什么?我已经看到一些使用XML文件,但是在我的情况似乎过分,因为数据文件只是决定游戏的水平,即障碍物将去的布局。

解决方案



如果你的文件是静态的,那么你需要将它们存储在应用程序包中(只需将它们添加到你的项目中; Xcode会在构建应用程序时将它们复制到.app包)。如果你需要修改和重新保存它们,大概〜/ Documents是你最好的选择。



Marc是正确的,NSDictionary是最简单的方法,特别是较小的文件。如果您有大量的数据,加载时可能会变慢,但这意味着10s或100s的千字节。还想想如果你喜欢它的内容,你的字典将转换为二进制格式,因为这将加载更快的设备上。


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!

解决方案

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.

这篇关于在iPhone上加载数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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