Fixing LabelAtlas to read texture relative to path of plist file

This commit is contained in:
Rohan Kuruvilla 2012-10-11 17:54:37 -07:00
parent 4af5abbc56
commit 540b41c091
1 changed files with 13 additions and 10 deletions

View File

@ -95,19 +95,22 @@ CCLabelAtlas* CCLabelAtlas::create(const char *string, const char *fntFile)
bool CCLabelAtlas::initWithString(const char *theString, const char *fntFile)
{
CCDictionary *dict = CCDictionary::createWithContentsOfFile(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fntFile));
CCAssert(((CCString*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
std::string pathStr = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(fntFile);
std::string relPathStr = pathStr.substr(0, pathStr.find_last_of("/"))+"/";
CCDictionary *dict = CCDictionary::createWithContentsOfFile(pathStr.c_str());
CCAssert(((CCString*)dict->objectForKey("version"))->intValue() == 1, "Unsupported version. Upgrade cocos2d version");
CCString *textureFilename = (CCString*)dict->objectForKey("textureFilename");
unsigned int width = ((CCString*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = ((CCString*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = ((CCString*)dict->objectForKey("firstChar"))->intValue();
std::string texturePathStr = relPathStr + ((CCString*)dict->objectForKey("textureFilename"))->getCString();
CCString *textureFilename = CCString::create(texturePathStr);
unsigned int width = ((CCString*)dict->objectForKey("itemWidth"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int height = ((CCString*)dict->objectForKey("itemHeight"))->intValue() / CC_CONTENT_SCALE_FACTOR();
unsigned int startChar = ((CCString*)dict->objectForKey("firstChar"))->intValue();
this->initWithString(theString, textureFilename->getCString(), width, height, startChar);
this->initWithString(theString, textureFilename->getCString(), width, height, startChar);
return true;
return true;
}
//CCLabelAtlas - Atlas generation