我想用cocos2d-x读取一个plist文件,如下所示:
x
0
y
0
x
140
y
12
x
120
y
280
x
40
y
364
它是由(x, y)形式的坐标组成的基础数组序列,我使用的初始代码如下:
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"w%i", world] ofType:@"plist"];
NSMutableArray* points = [NSMutableArray arrayWithContentsOfFile:path];
但是现在,我需要将上述代码翻译成用C++编写的cocos2d-x中,虽然用google搜索了一些文章,但是它们却无法解决我的问题,有没有人可以提供给我一个可利用的数组?
注:
现在,我更改了plist文件的格式:
11x
0
11y
0
12x
140
12y
12
但仍然出现一样的错误:
CCDictionary* dict = CCFileUtils::dictionaryWithContentsOfFile(plistPath);
int x = (int)dict->objectForKey("11x");
int y = (int)dict->objectForKey("11y");
我该如何解决?
原问题:cocos2d-x how to read plist into an array
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
答:NIKHIL
你可以尝试如下代码:
或者你也可以这样操作:
答:Inder Kumar Rathore
我不太清楚如何如何读取数组,所以,你可以先按如下方法更改plist文件:
然后:
答:m.ding
当你读取dictionary对象中的项目并使用ObjectForKey("BLA")命令时,你可以按照下述方法将它转换为CCString*: