Hi,all
I am new to cocos2d-x.The code I read is based on 1.0 while I’m learning 2.0.
Since I’m not familiar with both two versions,will someone come to my aid?
Thanks.
`// put in the name of the animation and the plist file - .plist
CCAnimation * GameObject::loadPlistForAnimationWithName(const char *animationName, const char *pszPlist)
{
CCAnimation *animationToReturn = NULL;
const char *plistPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
CCDictionary<std::string, CCObject*> *plistDictionary = CCFileUtils::dictionaryWithContentsOfFile(plistPath);
if (plistDictionary == NULL)
{
CCLOG("Error reading plist: %s", pszPlist);
return NULL;
}
//using a string to string dictionary to convert a CCString to float
CCDictionary<std::string, CCString*> *animationSettings = (CCDictionary<std::string, CCString*> *) plistDictionary->objectForKey(std::string(animationName));
if (animationSettings == NULL)
{
CCLOG("Could not locate AnimationWithName: %s", animationName);
return NULL;
}
float animationDelay = animationSettings->objectForKey(std::string("delay"))->toFloat();
animationToReturn = CCAnimation::animation();
animationToReturn->setDelay(animationDelay);
string animationFramePrefix = animationSettings->objectForKey(std::string("filenamePrefix"))->toStdString();
string animationFrames = animationSettings->objectForKey(std::string("animationFrames"))->toStdString();
vector<string> animationFrameNumbers = split(animationFrames, ',');
vector<string>::iterator it;
string frameNumber = "0";
for (it = animationFrameNumbers.begin(); it < animationFrameNumbers.end(); it++)
{
frameNumber = *it;
char frameName[100] = {0};
sprintf(frameName, "%s%s.png", animationFramePrefix.c_str(), frameNumber.c_str());
animationToReturn->addFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName));
}
return animationToReturn;
}
`