Example #1
0
	bool GameScene::loadGame()
	{
		BmsParser parser;
		bool parseResult = parser.compile(mSong->getPath().c_str(), mBmsDocument);
		if( !parseResult )
			return false;

		char* supportFormat[] = {"bmp", "jpg", "png"};
		int supportLen = sizeof(supportFormat) / sizeof(supportFormat[0]);

		// image(bga)
		for(auto it = mBmsDocument.bga().begin(); it != mBmsDocument.bga().end(); it++)
		{
			path fullpath = mBmsDocument.header().getParentPath() / it->second;
			if (is_regular_file(fullpath))
			{
				auto image = new Image;
				if (image->initWithImageFile(fullpath.string().c_str()))
				{
					mImageDictionary[it->first] = image;
					continue;
				}

				delete image;
			}

			// try alternatives
			for (const char* ext : supportFormat)
			{
				auto alter = fullpath.replace_extension(ext);
				if (is_regular_file(alter))
				{
					auto image = new Image;
					if (image->initWithImageFile(alter.string().c_str()))
					{
						mImageDictionary[it->first] = image;
						break;
					}

					delete image;
				}
			}
		}

		// wave
		for(auto it = mBmsDocument.wave().begin(); it != mBmsDocument.wave().end(); it++)
		{
			path fullpath = mBmsDocument.header().getParentPath() / it->second;
			mWavDictionary[it->first] = Audio::AudioManager::instance()->loadSound(fullpath.string().c_str());
		}

		return true;
	}
//AutoreleasePool pool;
bool ImageAlphaLut::initWithImage(std::string file)
{
    file = FileUtils::getInstance()->fullPathForFilename(file);
    auto na = file.substr(file.find_last_of("/") + 1);

    _name = (char *)malloc(na.length() + 1);
    strcpy(_name, na.c_str());


    auto img = new Image();

    CCASSERT(img->initWithImageFile(file), "Init image fail");

    auto lengh = img->getDataLen();
    CCASSERT(lengh >= 8, "NO image data");

    _width = img->getWidth();
    _height = img->getHeight();
    auto data = img->getData();
    // 初始化 BUFF
    resetBuffer();
    // 提取图片透明信息
    for (int i = 0 ; i < _width * _height; ++i)
    {
        if (data[i*4+3] )
        {
            setPixelAlpha(i);
        }
    }

    CC_SAFE_RELEASE(img);

    return true;
}
bool TigerAutoPolygonSprite::initWithFile(const std::string &file, bool usePolygon)
{
    if (usePolygon)
    {
        auto image = new Image();
        image->initWithImageFile(file);
        
        if (image->getRenderFormat() == Texture2D::PixelFormat::RGBA8888)
        {
            auto polygon_info = AutoPolygon::generatePolygon(file);
            
            if (!Sprite::initWithPolygon(polygon_info))
            {
                return false;
            }
        }
        else
        {
            if (!Sprite::initWithFile(file))
            {
                return false;
            }
        }
        
        CC_SAFE_DELETE(image);
    }
    else
    {
        if (!Sprite::initWithFile(file))
        {
            return false;
        }
    }
    
    return true;
}
Example #4
0
bool ScribbleTouchNode::useTarget(string pTargetFile){
    auto image = new Image();
    image->initWithImageFile(pTargetFile);
    restorePixes = calcute(image);
    return ScribbleNode::useTarget(pTargetFile);
}