SpriteFrameCache

来源:互联网 发布:linux dd u盘启动盘 编辑:程序博客网 时间:2024/05/16 06:24
class CC_DLL SpriteFrameCache : public Ref{public:    /** Adds multiple Sprite Frames from a plist file.     * A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png.     * If you want to use another texture, you should use the addSpriteFramesWithFile(const std::string& plist, const std::string& textureFileName) method.     * @js addSpriteFrames     * @lua addSpriteFrames     *     * @param plist Plist file name.     */    void addSpriteFramesWithFile(const std::string& plist);}void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist){    CCASSERT(plist.size()>0, "plist filename should not be nullptr");        std::string fullPath = FileUtils::getInstance()->fullPathForFilename(plist);    if (fullPath.size() == 0)    {        // return if plist file doesn't exist        CCLOG("cocos2d: SpriteFrameCache: can not find %s", plist.c_str());        return;    }    if (_loadedFileNames->find(plist) == _loadedFileNames->end())    {                ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(fullPath);        string texturePath("");        if (dict.find("metadata") != dict.end())        {            ValueMap& metadataDict = dict["metadata"].asValueMap();            // try to read  texture file name from meta data            texturePath = metadataDict["textureFileName"].asString();        }        if (!texturePath.empty())        {            // build texture path relative to plist file            texturePath = FileUtils::getInstance()->fullPathFromRelativeFile(texturePath.c_str(), plist);        }        else        {            // build texture path by replacing file extension            texturePath = plist;            // remove .xxx            size_t startPos = texturePath.find_last_of(".");             texturePath = texturePath.erase(startPos);            // append .png            texturePath = texturePath.append(".png");            CCLOG("cocos2d: SpriteFrameCache: Trying to use file %s as texture", texturePath.c_str());        }        Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(texturePath.c_str());        if (texture)        {            addSpriteFramesWithDictionary(dict, texture);            _loadedFileNames->insert(plist);        }        else        {            CCLOG("cocos2d: SpriteFrameCache: Couldn't load texture");        }    }}





0 0
原创粉丝点击