2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-06-08 14:11:48 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2009 Jason Booth
|
|
|
|
Copyright (c) 2009 Robert J Payne
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "cocoa/CCNS.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "CCTextureCache.h"
|
|
|
|
#include "CCSpriteFrameCache.h"
|
|
|
|
#include "CCSpriteFrame.h"
|
|
|
|
#include "CCSprite.h"
|
|
|
|
#include "support/TransformUtils.h"
|
|
|
|
#include "CCFileUtils.h"
|
|
|
|
#include "CCString.h"
|
|
|
|
#include "CCArray.h"
|
2012-06-08 14:11:48 +08:00
|
|
|
#include "CCDictionary.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
|
|
|
|
|
|
|
|
CCSpriteFrameCache* CCSpriteFrameCache::sharedSpriteFrameCache(void)
|
|
|
|
{
|
|
|
|
if (! pSharedSpriteFrameCache)
|
|
|
|
{
|
|
|
|
pSharedSpriteFrameCache = new CCSpriteFrameCache();
|
|
|
|
pSharedSpriteFrameCache->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return pSharedSpriteFrameCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(pSharedSpriteFrameCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCSpriteFrameCache::init(void)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames= new CCDictionary();
|
|
|
|
m_pSpriteFramesAliases = new CCDictionary();
|
2012-06-08 14:11:48 +08:00
|
|
|
m_pLoadedFileNames = new std::set<std::string>();
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSpriteFrameCache::~CCSpriteFrameCache(void)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(m_pSpriteFrames);
|
|
|
|
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
|
2012-06-08 14:11:48 +08:00
|
|
|
CC_SAFE_DELETE(m_pLoadedFileNames);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary* dictionary, CCTexture2D *pobTexture)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Supported Zwoptex Formats:
|
|
|
|
|
|
|
|
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+
|
|
|
|
*/
|
|
|
|
|
|
|
|
CCDictionary *metadataDict = (CCDictionary*)dictionary->objectForKey("metadata");
|
|
|
|
CCDictionary *framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
|
|
|
int format = 0;
|
|
|
|
|
|
|
|
// get the format
|
|
|
|
if(metadataDict != NULL)
|
|
|
|
{
|
|
|
|
format = metadataDict->valueForKey("format")->intValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the format
|
2012-06-08 14:11:48 +08:00
|
|
|
CCAssert(format >=0 && format <= 3, "format is not supported for CCSpriteFrameCache addSpriteFramesWithDictionary:textureFilename:");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCDictElement* pElement = NULL;
|
|
|
|
CCDICT_FOREACH(framesDict, pElement)
|
|
|
|
{
|
|
|
|
CCDictionary* frameDict = (CCDictionary*)pElement->getObject();
|
2012-06-12 09:31:36 +08:00
|
|
|
std::string spriteFrameName = pElement->getStrKey();
|
|
|
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(spriteFrameName);
|
2012-04-19 14:35:52 +08:00
|
|
|
if (spriteFrame)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(format == 0)
|
|
|
|
{
|
|
|
|
float x = frameDict->valueForKey("x")->floatValue();
|
|
|
|
float y = frameDict->valueForKey("y")->floatValue();
|
|
|
|
float w = frameDict->valueForKey("width")->floatValue();
|
|
|
|
float h = frameDict->valueForKey("height")->floatValue();
|
|
|
|
float ox = frameDict->valueForKey("offsetX")->floatValue();
|
|
|
|
float oy = frameDict->valueForKey("offsetY")->floatValue();
|
|
|
|
int ow = frameDict->valueForKey("originalWidth")->intValue();
|
|
|
|
int oh = frameDict->valueForKey("originalHeight")->intValue();
|
|
|
|
// check ow/oh
|
|
|
|
if(!ow || !oh)
|
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
CCLOGWARN("cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
// abs ow/oh
|
|
|
|
ow = abs(ow);
|
|
|
|
oh = abs(oh);
|
|
|
|
// create frame
|
|
|
|
spriteFrame = new CCSpriteFrame();
|
|
|
|
spriteFrame->initWithTexture(pobTexture,
|
|
|
|
CCRectMake(x, y, w, h),
|
|
|
|
false,
|
|
|
|
CCPointMake(ox, oy),
|
|
|
|
CCSizeMake((float)ow, (float)oh)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if(format == 1 || format == 2)
|
|
|
|
{
|
|
|
|
CCRect frame = CCRectFromString(frameDict->valueForKey("frame")->getCString());
|
|
|
|
bool rotated = false;
|
|
|
|
|
|
|
|
// rotation
|
|
|
|
if (format == 2)
|
|
|
|
{
|
|
|
|
rotated = frameDict->valueForKey("rotated")->boolValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCPoint offset = CCPointFromString(frameDict->valueForKey("offset")->getCString());
|
|
|
|
CCSize sourceSize = CCSizeFromString(frameDict->valueForKey("sourceSize")->getCString());
|
|
|
|
|
|
|
|
// create frame
|
|
|
|
spriteFrame = new CCSpriteFrame();
|
|
|
|
spriteFrame->initWithTexture(pobTexture,
|
|
|
|
frame,
|
|
|
|
rotated,
|
|
|
|
offset,
|
|
|
|
sourceSize
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (format == 3)
|
|
|
|
{
|
|
|
|
// get values
|
|
|
|
CCSize spriteSize = CCSizeFromString(frameDict->valueForKey("spriteSize")->getCString());
|
|
|
|
CCPoint spriteOffset = CCPointFromString(frameDict->valueForKey("spriteOffset")->getCString());
|
|
|
|
CCSize spriteSourceSize = CCSizeFromString(frameDict->valueForKey("spriteSourceSize")->getCString());
|
|
|
|
CCRect textureRect = CCRectFromString(frameDict->valueForKey("textureRect")->getCString());
|
|
|
|
bool textureRotated = frameDict->valueForKey("textureRotated")->boolValue();
|
|
|
|
|
|
|
|
// get aliases
|
|
|
|
CCArray* aliases = (CCArray*) (frameDict->objectForKey("aliases"));
|
2012-06-12 09:31:36 +08:00
|
|
|
CCString * frameKey = new CCString(spriteFrameName);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCObject* pObj = NULL;
|
|
|
|
CCARRAY_FOREACH(aliases, pObj)
|
|
|
|
{
|
|
|
|
std::string oneAlias = ((CCString*)pObj)->getCString();
|
|
|
|
if (m_pSpriteFramesAliases->objectForKey(oneAlias.c_str()))
|
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
CCLOGWARN("cocos2d: WARNING: an alias with name %s already exists", oneAlias.c_str());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
m_pSpriteFramesAliases->setObject(frameKey, oneAlias.c_str());
|
|
|
|
}
|
|
|
|
frameKey->release();
|
2011-03-29 11:56:14 +08:00
|
|
|
// create frame
|
|
|
|
spriteFrame = new CCSpriteFrame();
|
|
|
|
spriteFrame->initWithTexture(pobTexture,
|
|
|
|
CCRectMake(textureRect.origin.x, textureRect.origin.y, spriteSize.width, spriteSize.height),
|
|
|
|
textureRotated,
|
|
|
|
spriteOffset,
|
2012-04-19 14:35:52 +08:00
|
|
|
spriteSourceSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add sprite frame
|
2012-06-12 09:31:36 +08:00
|
|
|
m_pSpriteFrames->setObject(spriteFrame, spriteFrameName);
|
2012-04-19 14:35:52 +08:00
|
|
|
spriteFrame->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist, CCTexture2D *pobTexture)
|
|
|
|
{
|
2012-06-08 16:22:57 +08:00
|
|
|
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszPlist);
|
2012-06-14 16:05:58 +08:00
|
|
|
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(pszPath);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addSpriteFramesWithDictionary(dict, pobTexture);
|
|
|
|
|
|
|
|
dict->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char* plist, const char* textureFileName)
|
|
|
|
{
|
|
|
|
CCAssert(textureFileName, "texture name should not be null");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)
|
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
CCAssert(pszPlist, "plist filename should not be NULL");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 17:58:21 +08:00
|
|
|
if (m_pLoadedFileNames->find(pszPlist) == m_pLoadedFileNames->end())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-08 16:22:57 +08:00
|
|
|
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszPlist);
|
2012-06-14 16:05:58 +08:00
|
|
|
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(pszPath);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
string texturePath("");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
CCDictionary* metadataDict = (CCDictionary*)dict->objectForKey("metadata");
|
|
|
|
if (metadataDict)
|
|
|
|
{
|
|
|
|
// try to read texture file name from meta data
|
|
|
|
texturePath = metadataDict->valueForKey("textureFileName")->getCString();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
if (! texturePath.empty())
|
|
|
|
{
|
|
|
|
// build texture path relative to plist file
|
2012-06-08 16:22:57 +08:00
|
|
|
texturePath = CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(texturePath.c_str(), pszPath);
|
2012-06-08 14:11:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// build texture path by replacing file extension
|
|
|
|
texturePath = pszPath;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
// remove .xxx
|
|
|
|
size_t startPos = texturePath.find_last_of(".");
|
|
|
|
texturePath = texturePath.erase(startPos);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
// append .png
|
|
|
|
texturePath = texturePath.append(".png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: Trying to use file %s as texture", texturePath.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(texturePath.c_str());
|
|
|
|
|
|
|
|
if (pTexture)
|
|
|
|
{
|
|
|
|
addSpriteFramesWithDictionary(dict, pTexture);
|
|
|
|
m_pLoadedFileNames->insert(pszPlist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: Couldn't load texture");
|
|
|
|
}
|
|
|
|
|
|
|
|
dict->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::addSpriteFrame(CCSpriteFrame *pobFrame, const char *pszFrameName)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->setObject(pobFrame, pszFrameName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFrames(void)
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeAllObjects();
|
|
|
|
m_pSpriteFramesAliases->removeAllObjects();
|
2012-06-08 14:11:48 +08:00
|
|
|
m_pLoadedFileNames->clear();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeUnusedSpriteFrames(void)
|
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
bool bRemoved = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDictElement* pElement = NULL;
|
|
|
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
|
|
|
{
|
|
|
|
CCSpriteFrame* spriteFrame = (CCSpriteFrame*)pElement->getObject();
|
|
|
|
if( spriteFrame->retainCount() == 1 )
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCache: removing unused frame: %s", pElement->getStrKey());
|
|
|
|
m_pSpriteFrames->removeObjectForElememt(pElement);
|
2012-06-08 14:11:48 +08:00
|
|
|
bRemoved = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-06-12 01:43:07 +08:00
|
|
|
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
|
|
|
if( bRemoved )
|
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
m_pLoadedFileNames->clear();
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFrameByName(const char *pszName)
|
|
|
|
{
|
|
|
|
// explicit nil handling
|
|
|
|
if( ! pszName )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is this an alias ?
|
|
|
|
CCString* key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
|
|
|
|
|
|
|
if (key)
|
|
|
|
{
|
2012-04-26 11:39:49 +08:00
|
|
|
m_pSpriteFrames->removeObjectForKey(key->getCString());
|
|
|
|
m_pSpriteFramesAliases->removeObjectForKey(key->getCString());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pSpriteFrames->removeObjectForKey(pszName);
|
|
|
|
}
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-06-12 01:43:07 +08:00
|
|
|
// XXX. Since we don't know the .plist file that originated the frame, we must remove all .plist from the cache
|
2012-06-08 14:11:48 +08:00
|
|
|
m_pLoadedFileNames->clear();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromFile(const char* plist)
|
|
|
|
{
|
2012-06-08 16:22:57 +08:00
|
|
|
const char* path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plist);
|
2012-06-14 16:05:58 +08:00
|
|
|
CCDictionary* dict = CCDictionary::createWithContentsOfFileThreadSafe(path);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
removeSpriteFramesFromDictionary((CCDictionary*)dict);
|
|
|
|
|
2012-06-12 01:43:07 +08:00
|
|
|
// remove it from the cache
|
|
|
|
set<string>::iterator ret = m_pLoadedFileNames->find(plist);
|
|
|
|
if (ret != m_pLoadedFileNames->end())
|
|
|
|
{
|
|
|
|
m_pLoadedFileNames->erase(ret);
|
|
|
|
}
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
dict->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromDictionary(CCDictionary* dictionary)
|
|
|
|
{
|
|
|
|
CCDictionary* framesDict = (CCDictionary*)dictionary->objectForKey("frames");
|
2012-06-14 16:05:58 +08:00
|
|
|
CCArray* keysToRemove = CCArray::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCDictElement* pElement = NULL;
|
|
|
|
CCDICT_FOREACH(framesDict, pElement)
|
|
|
|
{
|
|
|
|
if (m_pSpriteFrames->objectForKey(pElement->getStrKey()))
|
|
|
|
{
|
2012-06-14 16:05:58 +08:00
|
|
|
keysToRemove->addObject(CCString::create(pElement->getStrKey()));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pSpriteFrames->removeObjectsForKeys(keysToRemove);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCSpriteFrameCache::removeSpriteFramesFromTexture(CCTexture2D* texture)
|
|
|
|
{
|
2012-06-14 16:05:58 +08:00
|
|
|
CCArray* keysToRemove = CCArray::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCDictElement* pElement = NULL;
|
|
|
|
CCDICT_FOREACH(m_pSpriteFrames, pElement)
|
|
|
|
{
|
|
|
|
string key = pElement->getStrKey();
|
|
|
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key.c_str());
|
|
|
|
if (frame && (frame->getTexture() == texture))
|
|
|
|
{
|
2012-06-14 16:05:58 +08:00
|
|
|
keysToRemove->addObject(CCString::create(pElement->getStrKey()));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pSpriteFrames->removeObjectsForKeys(keysToRemove);
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSpriteFrame* CCSpriteFrameCache::spriteFrameByName(const char *pszName)
|
|
|
|
{
|
|
|
|
CCSpriteFrame* frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(pszName);
|
|
|
|
if (!frame)
|
|
|
|
{
|
|
|
|
// try alias dictionary
|
|
|
|
CCString *key = (CCString*)m_pSpriteFramesAliases->objectForKey(pszName);
|
|
|
|
if (key)
|
|
|
|
{
|
2012-04-26 11:39:49 +08:00
|
|
|
frame = (CCSpriteFrame*)m_pSpriteFrames->objectForKey(key->getCString());
|
2012-04-19 14:35:52 +08:00
|
|
|
if (! frame)
|
|
|
|
{
|
|
|
|
CCLOG("cocos2d: CCSpriteFrameCahce: Frame '%s' not found", pszName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|