hello,I’m a rookie and I’m learning cocos2d-x recently.I want to initialize an array with the elements of dictionary like these code.But xcode sends an error that I using invalid parameter to initialize CCArray. Who can help me to recompose it? thank you!
CCDictionary *manifest = CCDictionary::createWithContentsOfFile(path);
change path to "preloadAssertManifest.plist".
if you need const char *path. use fullPathForFilename is a better choice. std::string pt = CCFileUtils::sharedFileUtils()->fullPathForFilename("preloadAssertManifest.plist");
CCArray *images = CCArray::createWithObject(manifest->objectForKey("Images"));
here, if you know you will get a CCArray, use createWithArray is a better choice. CCArray *images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));
[…]
if you need const char *path. use fullPathForFilename is a better choice. std::string pt = CCFileUtils::sharedFileUtils()->fullPathForFilename("preloadAssertManifest.plist");
> CCArray *images = CCArray::createWithObject(manifest->objectForKey("Images"));
here, if you know you will get a CCArray, use createWithArray is a better choice. CCArray *images = CCArray::createWithArray((CCArray*)manifest->objectForKey("Images"));
>
gook luck.
Hi qiao,thank you very much.I replaced the code as your answer,but the error is also existing.It says that the parameter “manifest->objectForKey(”Images“)” is invalid.
The array which get by the method of objecForKey maybe an empty array.
But also thanks for your help.
I think the question for “the parameter … is invalid.” is you missed (CCArray**).
it does use CCObject** force to CCArray*.then we can use CCArray::createWithArray.
hi.
did you use this line?
[…]
I think the question for “the parameter … is invalid.” is you missed (CCArray**).
it does use CCObject** force to CCArray*.then we can use CCArray::createWithArray.
Yeah,I use that line.But the project exited when createWithArray was invoked,like this:
i test this code in Xcode.
[…]
and it’s correct.
print:
[…]
>
i didn’t know the struct of your “preloadAssertManifest.plist”.
so i create a plist.
can you show me your plist?
ok,thank you,qiao.
I found the matter just now. My “.plist” file is error.
Now,it’s ok.
Thank you very much!