Esempio n. 1
0
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
{
	const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
	CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);

	return addSpriteFramesWithDictionary(dict, pobTexture);
}
Esempio n. 2
0
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
{
	const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
	CCDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
	
	string texturePath("");

	CCDictionary<std::string, CCObject*>* metadataDict = (CCDictionary<std::string, CCObject*>*)dict->objectForKey(string("metadata"));
    if (metadataDict)
	{
		// try to read  texture file name from meta data
		texturePath = string(valueForKey("textureFileName", metadataDict));
	}

	if (! texturePath.empty())
	{
		// build texture path relative to plist file

		// stringByDeletingLastPathComponent
		string textureBase(pszPath);
		int indexOfLastSeperator = textureBase.find_last_of('/');
        if (indexOfLastSeperator == textureBase.length() - 1)
		{
			textureBase.erase(indexOfLastSeperator, 1);
			indexOfLastSeperator = textureBase.find_last_of('/');
		}
		textureBase.erase(indexOfLastSeperator);

		// stringByAppendingPathComponent
        if (! textureBase.empty())
		{
			texturePath = textureBase + "/" + texturePath;
		}
	}
	else
	{
		// build texture path by replacing file extension
        texturePath = pszPath;

		// remove .xxx
		size_t startPos = texturePath.find_last_of("."); 
		texturePath = texturePath.erase(startPos);

		// append .png
		texturePath = texturePath.append(".png");

		CCLOG("cocos2d: CCSpriteFrameCache: Trying to use file %s as texture", texturePath);
	}

	CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(texturePath.c_str());

	if (pTexture)
	{
        addSpriteFramesWithDictionary(dict, pTexture);
	}
	else
	{
		CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
	}
}
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
{
	const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
	NSDictionary<std::string, NSObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
	
	string texturePath = string(pszPlist);

	// remove .xxx
	size_t startPos = texturePath.find_last_of("."); 
	texturePath = texturePath.erase(startPos);

	// append .png
	texturePath = texturePath.append(".png");

	CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(texturePath.c_str());

	return addSpriteFramesWithDictionary(dict, pTexture);
}