i want to read a 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’s basically an array of dictionary that consist of (x, y) coordinates.
my original code for reading is:
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’ve googled some article but they are all about reading plist into dictionary. i need an array.
EDIT:::
Now i’ve 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");
won’t work.
Please try it out first. see if you can read a int from the sample plist
Try the follwing line of code
EDIT
or you can try this too…
EDIT-2
Try Following code in case of root is Dictionary
Look Inside
CCParticleSystem.cppclass you might get batter idea.check
bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *dictionary)insideCCParticleSystem.cppclassRegards,
Nikhil