From 0469632cf8ca98fb21369f66ae3269b9c471842f Mon Sep 17 00:00:00 2001 From: KURA Shuichi Date: Sat, 3 Oct 2015 03:18:07 +0900 Subject: [PATCH] Inprove addSpriteFramesWithDictionary - Moved initialization of image to an appropriate location, because it always called twice in SpriteFrameCache::addSpriteFramesWithFile() --- cocos/2d/CCSpriteFrameCache.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index 3588ad2b7c..0935b7aeab 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -105,8 +105,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu CCASSERT(format >=0 && format <= 3, "format is not supported for SpriteFrameCache addSpriteFramesWithDictionary:textureFilename:"); auto textureFileName = Director::getInstance()->getTextureCache()->getTextureFilePath(texture); - auto image = new Image(); - image->initWithImageFile(textureFileName); + Image* image = nullptr; NinePatchImageParser parser; for (auto iter = framesDict.begin(); iter != framesDict.end(); ++iter) { @@ -199,6 +198,10 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu bool flag = NinePatchImageParser::isNinePatchImage(spriteFrameName); if(flag) { + if (image == nullptr) { + image = new Image(); + image->initWithImageFile(textureFileName); + } parser.setSpriteFrameInfo(image, spriteFrame->getRectInPixels(), spriteFrame->isRotated()); texture->addSpriteFrameCapInset(spriteFrame, parser.parseCapInset()); }