CSLader加载plist

来源:互联网 发布:知乐小说作品集百度云 编辑:程序博客网 时间:2024/06/07 02:36
Node* CSLoader::createNode(const std::string& filename){    std::string path = filename;    size_t pos = path.find_last_of('.');    std::string suffix = path.substr(pos + 1, path.length());        CSLoader* load = CSLoader::getInstance();    if (suffix == "csb")    {        return load->createNodeWithFlatBuffersFile(filename);    }    else if (suffix == "json" || suffix == "ExportJson")    {        return load->createNodeFromJson(filename);    }    return nullptr;}Node* CSLoader::createNodeWithFlatBuffersFile(const std::string &filename, const ccNodeLoadCallback &callback){    Node* node = nodeWithFlatBuffersFile(filename, callback);    reconstructNestNode(node);    return node;}Node* CSLoader::nodeWithFlatBuffersFile(const std::string &fileName, const ccNodeLoadCallback &callback){    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);        CC_ASSERT(FileUtils::getInstance()->isFileExist(fullPath));        Data buf = FileUtils::getInstance()->getDataFromFile(fullPath);    if (buf.isNull())    {        CCLOG("CSLoader::nodeWithFlatBuffersFile - failed read file: %s", fileName.c_str());        CC_ASSERT(false);        return nullptr;    }    auto csparsebinary = GetCSParseBinary(buf.getBytes());            auto csBuildId = csparsebinary->version();    if (csBuildId)    {        CCASSERT(strcmp(_csBuildID.c_str(), csBuildId->c_str()) == 0,                 StringUtils::format("%s%s%s%s%s%s%s%s%s%s",                                          "The reader build id of your Cocos exported file(",                                          csBuildId->c_str(),                                          ") and the reader build id in your Cocos2d-x(",                                          _csBuildID.c_str(),                                          ") are not match.\n",                                          "Please get the correct reader(build id ",                                          csBuildId->c_str(),                                          ")from ",                                          "http://www.cocos2d-x.org/filedown/cocos-reader",                                          " and replace it in your Cocos2d-x").c_str());    }        // decode plist    auto textures = csparsebinary->textures();    int textureSize = textures->size();    for (int i = 0; i < textureSize; ++i)    {        SpriteFrameCache::getInstance()->addSpriteFramesWithFile(textures->Get(i)->c_str());    }        Node* node = nodeWithFlatBuffers(csparsebinary->nodeTree(), callback);        return node;}

可以看出来,会加载plist中用到的图片到SpriteFrameCache中的。




原创粉丝点击