2010-07-30 14:10:45 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
#include "platform/CCNS.h"
|
2010-07-30 14:10:45 +08:00
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCTextureCache.h"
|
|
|
|
#include "CCSpriteFrameCache.h"
|
|
|
|
#include "CCSpriteFrame.h"
|
|
|
|
#include "CCSprite.h"
|
|
|
|
#include "support/TransformUtils.h"
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCFileUtils.h"
|
|
|
|
#include "CCString.h"
|
2010-07-30 14:10:45 +08:00
|
|
|
|
2010-08-04 15:46:12 +08:00
|
|
|
namespace cocos2d {
|
2010-07-30 14:10:45 +08:00
|
|
|
|
|
|
|
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
|
|
|
|
|
|
|
CCSpriteFrameCache* CCSpriteFrameCache::sharedSpriteFrameCache(void)
|
|
|
|
{
|
|
|
|
if (! pSharedSpriteFrameCache)
|
|
|
|
{
|
|
|
|
pSharedSpriteFrameCache = new CCSpriteFrameCache();
|
|
|
|
pSharedSpriteFrameCache->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSharedSpriteFrameCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(pSharedSpriteFrameCache);
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
2010-09-04 12:02:52 +08:00
|
|
|
bool CCSpriteFrameCache::init(void)
|
2010-07-30 14:10:45 +08:00
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames= new NSDictionary<std::string, CCSpriteFrame*>();
|
2010-12-27 10:26:56 +08:00
|
|
|
m_pSpriteFramesAliases = new NSDictionary<std::string, CCSpriteFrame*>();
|
2010-09-04 12:02:52 +08:00
|
|
|
return true;
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCSpriteFrameCache::~CCSpriteFrameCache(void)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames->release();
|
2010-12-27 10:26:56 +08:00
|
|
|
m_pSpriteFramesAliases->release();
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithDictionary(NSDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)
|
2010-07-30 14:10:45 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Supported Zwoptex Formats:
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
ZWTCoordinatesFormatOptionXMLLegacy = 0, // Flash Version
|
|
|
|
ZWTCoordinatesFormatOptionXML1_0 = 1, // Desktop Version 0.0 - 0.4b
|
|
|
|
ZWTCoordinatesFormatOptionXML1_1 = 2, // Desktop Version 1.0.0 - 1.0.1
|
|
|
|
ZWTCoordinatesFormatOptionXML1_2 = 3, // Desktop Version 1.0.2+
|
2010-07-30 14:10:45 +08:00
|
|
|
*/
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *metadataDict = (NSDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("metadata"));
|
|
|
|
NSDictionary<std::string, CCObject*> *framesDict = (NSDictionary<std::string, CCObject*>*)dictionary->objectForKey(std::string("frames"));
|
2010-09-10 14:08:25 +08:00
|
|
|
int format = 0;
|
|
|
|
|
|
|
|
// get the format
|
|
|
|
if(metadataDict != NULL)
|
|
|
|
{
|
|
|
|
format = atoi(valueForKey("format", metadataDict));
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the format
|
2010-12-27 10:26:56 +08:00
|
|
|
assert(format >=0 && format <= 3);
|
2010-09-10 14:08:25 +08:00
|
|
|
|
|
|
|
framesDict->begin();
|
|
|
|
std::string key = "";
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
|
|
while( frameDict = (NSDictionary<std::string, CCObject*>*)framesDict->next(&key) )
|
2010-09-10 14:08:25 +08:00
|
|
|
{
|
|
|
|
CCSpriteFrame *spriteFrame = m_pSpriteFrames->objectForKey(key);
|
|
|
|
if (spriteFrame)
|
2010-07-30 14:10:45 +08:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-10 14:08:25 +08:00
|
|
|
|
|
|
|
if(format == 0)
|
|
|
|
{
|
|
|
|
float x = (float)atof(valueForKey("x", frameDict));
|
|
|
|
float y = (float)atof(valueForKey("y", frameDict));
|
|
|
|
float w = (float)atof(valueForKey("width", frameDict));
|
|
|
|
float h = (float)atof(valueForKey("height", frameDict));
|
|
|
|
float ox = (float)atof(valueForKey("offsetX", frameDict));
|
|
|
|
float oy = (float)atof(valueForKey("offsetY", frameDict));
|
|
|
|
int ow = atoi(valueForKey("originalWidth", frameDict));
|
|
|
|
int oh = atoi(valueForKey("originalHeight", frameDict));
|
|
|
|
// check ow/oh
|
|
|
|
if(!ow || !oh)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
|
|
|
|
}
|
|
|
|
// abs ow/oh
|
|
|
|
ow = abs(ow);
|
|
|
|
oh = abs(oh);
|
|
|
|
// create frame
|
2010-12-27 10:26:56 +08:00
|
|
|
spriteFrame = new CCSpriteFrame();
|
|
|
|
spriteFrame->initWithTexture(pobTexture,
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRectMake(x, y, w, h),
|
2010-12-27 10:26:56 +08:00
|
|
|
false,
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPointMake(ox, oy),
|
|
|
|
CCSizeMake((float)ow, (float)oh)
|
2010-12-27 10:26:56 +08:00
|
|
|
);
|
2010-09-10 14:08:25 +08:00
|
|
|
}
|
2010-12-27 10:26:56 +08:00
|
|
|
else if(format == 1 || format == 2)
|
2010-09-10 14:08:25 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCRect frame = CCRectFromString(valueForKey("frame", frameDict));
|
2010-12-27 10:26:56 +08:00
|
|
|
bool rotated = false;
|
|
|
|
|
|
|
|
// rotation
|
|
|
|
if (format == 2)
|
|
|
|
{
|
|
|
|
rotated = atoi(valueForKey("rotated", frameDict)) == 0 ? false : true;
|
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
CCPoint offset = CCPointFromString(valueForKey("offset", frameDict));
|
|
|
|
CCSize sourceSize = CCSizeFromString(valueForKey("sourceSize", frameDict));
|
2010-12-27 10:26:56 +08:00
|
|
|
|
2010-07-30 14:10:45 +08:00
|
|
|
// create frame
|
2010-12-27 10:26:56 +08:00
|
|
|
spriteFrame = new CCSpriteFrame();
|
|
|
|
spriteFrame->initWithTexture(pobTexture,
|
|
|
|
frame,
|
|
|
|
rotated,
|
|
|
|
offset,
|
|
|
|
sourceSize
|
|
|
|
);
|
|
|
|
} else
|
|
|
|
if (format == 3)
|
2010-09-24 18:10:32 +08:00
|
|
|
{
|
2010-12-27 10:26:56 +08:00
|
|
|
/// @todo what's the format look like?
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
// get values
|
2011-03-07 17:11:57 +08:00
|
|
|
CCSize spriteSize = CCSizeFromString(valueForKey("spriteSize", frameDict));
|
|
|
|
CCPoint spriteOffset = CCPointFromString(valueForKey("spriteOffset", frameDict));
|
|
|
|
CCSize spriteSourceSize = CCSizeFromString(valueForKey("spriteSourceSize", frameDict));
|
|
|
|
CCRect textureRect = CCRectFromString(valueForKey("textureRect", frameDict));
|
2010-12-27 10:26:56 +08:00
|
|
|
bool textureRotated = atoi(valueForKey("textureRotated", frameDict)) == 0;
|
|
|
|
|
|
|
|
// get aliases
|
2011-03-07 17:11:57 +08:00
|
|
|
NSArray<CCString*> *aliases = NSArray<CCString*>dictionary->objectForKey(std::string("aliases"));
|
2010-12-27 10:26:56 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
while( alias = (NSDictionary<std::string, CCObject*>*)aliases->next(&key) )
|
2010-12-27 10:26:56 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
std::string value = ((CCString*)alias->objectForKey(key))->m_sString();
|
2010-12-27 10:26:56 +08:00
|
|
|
if (m_pSpriteFramesAliases->objectForKey(value))
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: WARNING: an alias with name %s already exists", value.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pSpriteFramesAliases->setObject(frameDict, value);
|
|
|
|
}
|
|
|
|
*/
|
2010-09-24 18:10:32 +08:00
|
|
|
}
|
2010-12-27 10:26:56 +08:00
|
|
|
|
2010-09-10 14:08:25 +08:00
|
|
|
// add sprite frame
|
|
|
|
m_pSpriteFrames->setObject(spriteFrame, key);
|
2010-12-27 10:26:56 +08:00
|
|
|
spriteFrame->release();
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
|
|
|
{
|
2010-09-07 16:30:31 +08:00
|
|
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
2010-08-03 13:52:41 +08:00
|
|
|
|
|
|
|
return addSpriteFramesWithDictionary(dict, pobTexture);
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
|
|
|
{
|
|
|
|
assert(textureFileName);
|
|
|
|
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(textureFileName);
|
|
|
|
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
addSpriteFramesWithFile(plist, texture);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: couldn't load texture file. File not found %s", textureFileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 14:10:45 +08:00
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
|
|
|
{
|
2010-09-07 16:30:31 +08:00
|
|
|
const char *pszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *dict = CCFileUtils::dictionaryWithContentsOfFile(pszPath);
|
2010-08-03 13:52:41 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
string texturePath("");
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*>* metadataDict = (NSDictionary<std::string, CCObject*>*)dict->objectForKey(string("metadata"));
|
2010-12-27 10:26:56 +08:00
|
|
|
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
|
2011-01-05 17:01:08 +08:00
|
|
|
string textureBase(pszPath);
|
2010-12-27 10:26:56 +08:00
|
|
|
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
|
2011-01-05 17:01:08 +08:00
|
|
|
texturePath = pszPath;
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
// remove .xxx
|
|
|
|
size_t startPos = texturePath.find_last_of(".");
|
|
|
|
texturePath = texturePath.erase(startPos);
|
2010-08-03 13:52:41 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
// append .png
|
|
|
|
texturePath = texturePath.append(".png");
|
2010-08-03 13:52:41 +08:00
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: Trying to use file %s as texture", texturePath);
|
|
|
|
}
|
2010-08-03 13:52:41 +08:00
|
|
|
|
|
|
|
CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(texturePath.c_str());
|
|
|
|
|
2010-12-27 10:26:56 +08:00
|
|
|
if (pTexture)
|
|
|
|
{
|
|
|
|
addSpriteFramesWithDictionary(dict, pTexture);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
|
|
|
|
}
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames->setObject(pobFrame, std::string(pszFrameName));
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFrames(void)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames->removeAllObjects();
|
2010-12-27 10:26:56 +08:00
|
|
|
m_pSpriteFramesAliases->removeAllObjects();
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames->begin();
|
|
|
|
std::string key = "";
|
|
|
|
CCSpriteFrame *spriteFrame = NULL;
|
|
|
|
while( spriteFrame = m_pSpriteFrames->next(&key) )
|
|
|
|
{
|
|
|
|
if( spriteFrame->retainCount() == 1 )
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", key.c_str());
|
|
|
|
m_pSpriteFrames->removeObjectForKey(key);
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-10 14:08:25 +08:00
|
|
|
m_pSpriteFrames->end();
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
|
|
|
{
|
2010-12-27 10:26:56 +08:00
|
|
|
// explicit nil handling
|
|
|
|
if( ! pszName )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this an alias ?
|
2011-03-07 17:11:57 +08:00
|
|
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
if (key)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeObjectForKey(key->m_sString);
|
|
|
|
m_pSpriteFramesAliases->removeObjectForKey(key->m_sString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeObjectForKey(std::string(pszName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
|
|
|
{
|
|
|
|
const char* path = CCFileUtils::fullPathFromRelativePath(plist);
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*>* dict = CCFileUtils::dictionaryWithContentsOfFile(path);
|
2010-12-27 10:26:56 +08:00
|
|
|
|
|
|
|
removeSpriteFramesFromDictionary((NSDictionary<std::string, CCSpriteFrame*>*)dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(NSDictionary<std::string, CCSpriteFrame*> *dictionary)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*>* framesDict = (NSDictionary<std::string, CCObject*>*)dictionary->objectForKey(string("frames"));
|
2010-12-27 10:26:56 +08:00
|
|
|
vector<string> keysToRemove;
|
|
|
|
|
|
|
|
framesDict->begin();
|
|
|
|
std::string key = "";
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
|
|
while( frameDict = (NSDictionary<std::string, CCObject*>*)framesDict->next(&key) )
|
2010-12-27 10:26:56 +08:00
|
|
|
{
|
|
|
|
if (m_pSpriteFrames->objectForKey(key))
|
|
|
|
{
|
|
|
|
keysToRemove.push_back(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
framesDict->end();
|
|
|
|
|
|
|
|
vector<string>::iterator iter;
|
|
|
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); iter++)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeObjectForKey(*iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromTexture(CCTexture2D* texture)
|
|
|
|
{
|
|
|
|
vector<string> keysToRemove;
|
|
|
|
|
|
|
|
m_pSpriteFrames->begin();
|
|
|
|
std::string key = "";
|
2011-03-07 17:11:57 +08:00
|
|
|
NSDictionary<std::string, CCObject*> *frameDict = NULL;
|
|
|
|
while( frameDict = (NSDictionary<std::string, CCObject*>*)m_pSpriteFrames->next(&key) )
|
2010-12-27 10:26:56 +08:00
|
|
|
{
|
|
|
|
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(key);
|
|
|
|
if (frame && (frame->getTexture() == texture))
|
|
|
|
{
|
|
|
|
keysToRemove.push_back(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_pSpriteFrames->end();
|
|
|
|
|
|
|
|
vector<string>::iterator iter;
|
|
|
|
for (iter = keysToRemove.begin(); iter != keysToRemove.end(); iter++)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeObjectForKey(*iter);
|
|
|
|
}
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(std::string(pszName));
|
2010-12-27 10:26:56 +08:00
|
|
|
if (! frame)
|
2010-09-10 14:08:25 +08:00
|
|
|
{
|
2010-12-27 10:26:56 +08:00
|
|
|
// try alias dictionary
|
2011-03-07 17:11:57 +08:00
|
|
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(string(pszName));
|
2010-12-27 10:26:56 +08:00
|
|
|
if (key)
|
|
|
|
{
|
|
|
|
frame = m_pSpriteFrames->objectForKey(key->m_sString);
|
|
|
|
if (! frame)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
|
|
|
}
|
|
|
|
}
|
2010-09-10 14:08:25 +08:00
|
|
|
}
|
|
|
|
return frame;
|
2010-07-30 14:10:45 +08:00
|
|
|
}
|
2010-08-03 13:52:41 +08:00
|
|
|
|
|
|
|
CCSprite* CCSpriteFrameCache::createSpriteWithFrameName(const char *pszName)
|
|
|
|
{
|
2010-09-10 14:08:25 +08:00
|
|
|
CCSpriteFrame *frame = m_pSpriteFrames->objectForKey(std::string(pszName));
|
|
|
|
return CCSprite::spriteWithSpriteFrame(frame);
|
|
|
|
}
|
2011-03-07 17:11:57 +08:00
|
|
|
const char * CCSpriteFrameCache::valueForKey(const char *key, NSDictionary<std::string, CCObject*> *dict)
|
2010-09-10 14:08:25 +08:00
|
|
|
{
|
|
|
|
if (dict)
|
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
CCString *pString = (CCString*)dict->objectForKey(std::string(key));
|
2010-09-10 14:08:25 +08:00
|
|
|
return pString ? pString->m_sString.c_str() : "";
|
|
|
|
}
|
|
|
|
return "";
|
2010-08-03 13:52:41 +08:00
|
|
|
}
|
2010-08-04 15:46:12 +08:00
|
|
|
}//namespace cocos2d
|