void Cocos2dxFactory::loadTextureAtlasFile(const String &textureAtlasFile , const String &name)
 {
     dragonBones::XMLDataParser parser;
     unsigned long dummySize;
     
     dragonBones::XMLDocument doc;
     unsigned char* texture_data = CCFileUtils::sharedFileUtils()->
     getFileData(textureAtlasFile.c_str(), "rb", &dummySize);
     doc.Parse(reinterpret_cast<char*>(texture_data), dummySize);
     delete[] texture_data;
     
     int pos = textureAtlasFile.find_last_of("/");
     if (std::string::npos != pos){
         std::string base_path = textureAtlasFile.substr(0, pos + 1);
         
         std::string img_path = doc.RootElement()->Attribute(ConstValues::A_IMAGE_PATH.c_str());
         std::string new_img_path = base_path + img_path;
         
         doc.RootElement()->SetAttribute(ConstValues::A_IMAGE_PATH.c_str(), new_img_path.c_str());
     }
     
     TextureAtlasData *textureAtlasData = parser.parseTextureAtlasData(doc.RootElement());
     addTextureAtlas(new dragonBones::Cocos2dxTextureAtlas(textureAtlasData));
     
 }
// 加载纹理集数据
ITextureAtlas* DBCCFactoryEx::loadDotaTextureAtlas(
	const std::string &fcaFile,
	const std::string &name/* = ""*/)
{
	ITextureAtlas *existTextureAtlas = getTextureAtlas(name);

	if (existTextureAtlas)
	{
		refreshTextureAtlasTexture(name.empty() ? existTextureAtlas->textureAtlasData->name : name);
		return existTextureAtlas;
	}

	// textureAtlas scale
	float scale = cocos2d::Director::getInstance()->getContentScaleFactor();

	DotaAnimParser parser;
	DBCCTextureAtlasEx *textureAtlas = new DBCCTextureAtlasEx();
	textureAtlas->_fcaFile = fcaFile;
	textureAtlas->textureAtlasData = parser.parseTextureAtlasData(fcaFile, scale);
	textureAtlas->textureAtlasData->name = name;

	addTextureAtlas(textureAtlas, name);
	refreshTextureAtlasTexture(name.empty() ? textureAtlas->textureAtlasData->name : name);
	return textureAtlas;
}
Beispiel #3
0
ITextureAtlas* DBCCFactory::loadTextureAtlas(const std::string &textureAtlasFile, const std::string &name)
{
    ITextureAtlas *existTextureAtlas = getTextureAtlas(name);

    if (existTextureAtlas)
    {
        refreshTextureAtlasTexture(name.empty() ? existTextureAtlas->textureAtlasData->name : name);
        return existTextureAtlas;
    }

    const auto &data = cocos2d::FileUtils::getInstance()->getDataFromFile(textureAtlasFile);
    if (data.getSize() == 0)
    {
        return nullptr;
    }

    // textureAtlas scale
    float scale = cocos2d::Director::getInstance()->getContentScaleFactor();

    dragonBones::XMLDocument doc;
    doc.Parse(reinterpret_cast<char*>(data.getBytes()), data.getSize());
    dragonBones::XMLDataParser parser;
    DBCCTextureAtlas *textureAtlas = new DBCCTextureAtlas();
    textureAtlas->textureAtlasData = parser.parseTextureAtlasData(doc.RootElement(), scale);

    int pos = textureAtlasFile.find_last_of("/");

    if (std::string::npos != pos)
    {
        std::string base_path = textureAtlasFile.substr(0, pos + 1);
        textureAtlas->textureAtlasData->imagePath = base_path + textureAtlas->textureAtlasData->imagePath;
    }

    //
    addTextureAtlas(textureAtlas, name);
    refreshTextureAtlasTexture(name.empty() ? textureAtlas->textureAtlasData->name : name);
    return textureAtlas;
}
		void Cocos2dxFactory::loadTextureAtlasFile(const String &textureAtlasFile , const String &name)
		{
			dragonBones::XMLDataParser parser;
			// 载入皮肤数据
			dragonBones::XMLDocument doc;
			auto date = cocos2d::FileUtils::getInstance()->getDataFromFile(textureAtlasFile);
			doc.Parse(reinterpret_cast<char*>(date.getBytes()), date.getSize());

			int pos = textureAtlasFile.find_last_of("/");
			if (std::string::npos != pos){
				std::string base_path = textureAtlasFile.substr(0, pos + 1);
				
				std::string img_path = doc.RootElement()->Attribute(ConstValues::A_IMAGE_PATH.c_str());
				std::string new_img_path = base_path + img_path;

				doc.RootElement()->SetAttribute(ConstValues::A_IMAGE_PATH.c_str(), new_img_path.c_str());
			}

			// 解析皮肤数据
			TextureAtlasData *textureAtlasData = parser.parseTextureAtlasData(doc.RootElement());
			addTextureAtlas(new dragonBones::Cocos2dxTextureAtlas(textureAtlasData));

		}