从 plist 问题创建数组
首先,介绍一下背景。我正在尝试制作一款平台游戏。在游戏层前面,我希望“灯光”经过,灯光是指白色三角形。我正在尝试从 plist 中获取三角形的坐标。
此时,我花了几天时间尝试让我的应用程序从 plist 中读取数据,但无法让它工作。 这就是我目前拥有的,这基本上就是互联网上所说的我应该拥有的并且它应该有效。
在 helloWorld.h 中:
NSMutableArray *foregroundLights;
在 helloWorld.m 中,
NSString *path = [[NSBundle mainBundle] pathForResource:@"foregroundlights" ofType:@"plist"];
foregroundLights = [[NSMutableArray alloc] initWithContentsOfFile:path];
我尝试以我能想到的各种方式格式化补丁,我尝试使用 NSSearchPathsForDirectoriesInDomains。我尝试将 plist 设为字典并将其设为数组。我缺少什么?
这是 plist 的一部分。完整的数组包含 50 个 4 个整数的数组。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>root</key>
<array>
<array>
<integer>128</integer>
<integer>68</integer>
<integer>246</integer>
<integer>7</integer>
</array>
<array>
<integer>181</integer>
<integer>84</integer>
<integer>170</integer>
<integer>62</integer>
</array>
<array>
<integer>118</integer>
<integer>51</integer>
<integer>142</integer>
<integer>64</integer>
</array>
</array>
</dict>
</plist>
First, a little background. I am trying to make a platform game. In front of the game layer I want "lights" to go by and by lights I mean white triangles. I am trying to get coordinates for the triangles from a plist.
At this point I have spent days trying to get my app to read from a plist and I cannot get it to work.
This is what I currently have and this is basically what the internet is saying I should have and that it should work.
In helloWorld.h:
NSMutableArray *foregroundLights;
In helloWorld.m
NSString *path = [[NSBundle mainBundle] pathForResource:@"foregroundlights" ofType:@"plist"];
foregroundLights = [[NSMutableArray alloc] initWithContentsOfFile:path];
I have tried formatting the patch every way that I can think of, I have tried using NSSearchPathsForDirectoriesInDomains. I have tried making the plist a dictionary and making it an array. What am I missing?
Here is a piece of the plist. The full one contains 50 arrays of 4 ints.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>root</key>
<array>
<array>
<integer>128</integer>
<integer>68</integer>
<integer>246</integer>
<integer>7</integer>
</array>
<array>
<integer>181</integer>
<integer>84</integer>
<integer>170</integer>
<integer>62</integer>
</array>
<array>
<integer>118</integer>
<integer>51</integer>
<integer>142</integer>
<integer>64</integer>
</array>
</array>
</dict>
</plist>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论