I want to read plist using cocos2d-x (C ++) here is my plist:
<array> <dict> <key>x</key> <integer>0</integer> <key>y</key> <integer>0</integer> </dict> <dict> <key>x</key> <integer>140</integer> <key>y</key> <integer>12</integer> </dict> <dict> <key>x</key> <integer>120</integer> <key>y</key> <integer>280</integer> </dict> <dict> <key>x</key> <integer>40</integer> <key>y</key> <integer>364</integer> </dict> <array>
it is basically a dictionary array consisting of (x, y) coordinates. my source code to read:
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"w%i", world] ofType:@"plist"]; NSMutableArray* points = [NSMutableArray arrayWithContentsOfFile:path];
but now I need to translate it into cocos2d-x in C ++. I was looking for an article, but they all relate to reading plist in a dictionary. I need an array.
EDIT:
Now I changed my plist format:
<dict> <key>11x</key> <integer>0</integer> <key>11y</key> <integer>0</integer> <key>12x</key> <integer>140</integer> <key>12y</key> <integer>12</integer> <dict>
what should I do??? I still get the same error:
CCDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFile(plistPath); int x = (int)dict->objectForKey("11x"); int y = (int)dict->objectForKey("11y");
will not work. Try it first. see if you can read int from plist sample
source share