On the rookie can learn cocos2dx3.0 Turret Legend (lower)

First of all we are talking about things outside the points, then loaded asynchronously: we all know. loading data which are generally loaded, then how is it loaded?

Director::getInstance()->getTextureCache()->addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback)//參数1。文件路径,參数2,回调函数(一般都是进度条)

So suppose we want to load frame animation it?

auto frameache=SpriteFrameCache::getInstance();
frameache->addSpriteFramesWithFile(" xxxxxx  ");//參数。plist文件路径

But this is not loaded asynchronously. So how should we do? In fact still with the above two:

Director::getInstance()->getTextureCache()->addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback);//我们首先异步载入了纹理
auto My_Texture2D=Director::getInstance()->getTextureCache()->addImage(" ");

After // Suppose we successfully loaded asynchronously picture, we can from the texture cache inside that std :: unordered_map <std :: string, Texture2D *> _textures returns the corresponding key texture. The key in the source code engine is the full path to the file, which will be due in texture2d step std :: string fullpath = FileUtils :: getInstance () -> fullPathForFilename (path); and our external use, it only needs the usual resources of path can be.

Or directly auto cache = SpriteFrameCache :: getInstance (); cache-> addSpriteFramesWithFile ( "plist Path", "png path");

auto frameache=SpriteFrameCache::getInstance();
frameache->addSpriteFramesWithFile(" xxxxxx  ",My_Texture2D);//參数1。plist文件路径,參数2,纹理  这样我们就能完毕异步载入帧动画了~

Get to the turret legend:

First, we extract the dota package. You will find


A black background and a grayscale chart jpg, png on the map is not with alpha, alpha, but not jpg. So Turret legendary why is that?

Here is my personal understanding:

jpg image pixel map is compressed. The other is actually a grayscale comes with 8 channels of transparent png, so we just want to grayscale alpha copy the past, will be able to achieve jpg background hollow.

Such words can reduce the image size of the resource. After all, you jpg is compressed. png decisive equivalent to a large hollow is very much here can determine jpg + 8-bit grayscale <png.

Under then do so where the advantages of it, yes, that is very much in the picture resource situation. We clearly have to feel the advantage of using this picture format : a, can make your application less , because the picture is of a compressed. Second, you can start the game faster.

Principle and pvr.ccz somewhat similar. But pvr.ccz has its unique advantages, is pvr format can be directly ios card recognized. Than png safer, to avoid a large number of loaded memory problems.

and then. How should we use jpg + effect grayscale texture hollow realize it?

Look engine code!

Texture2D * TextureCache::addImage(const std::string &path)
{
    Texture2D * texture = nullptr;
    Image* image = nullptr;
    // Split up directory and filename
    // MUTEX:
    // Needed since addImageAsync calls this method from a different thread

    std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path);//获取完整路径
    if (fullpath.size() == 0)
    {
        return nullptr;
    }
    auto it = _textures.find(fullpath);//在缓存中查找是否是已经载入过的纹理图片
    if( it != _textures.end() )
        texture = it->second;

    if (! texture)//假设是未被加过的纹理
    {
        // all images are handled by UIImage except PVR extension that is handled by our own handler
        do 
        {
            image = new Image();//创建一个image对象,imgae对象中封装了libjpeg,即jpg的解压/压缩库,另外利用了FileUtils::getInstance()->getDataFromFile(_filePath)  FileUtils默认会以rb模式读取二进制的数据信息
            CC_BREAK_IF(nullptr == image);

            bool bRet = image->initWithImageFile(fullpath);//将FileUtiles读取的数据用jpeg进行解压,期间有个图片格式的推断
            CC_BREAK_IF(!bRet);
		
            texture = new Texture2D();

            if( texture && texture->initWithImage(image) )//载入纹理将rgb888的jpg转为rgba8888
            {
#if CC_ENABLE_CACHE_TEXTURE_DATA
                // cache the texture file name
                VolatileTextureMgr::addImageTexture(texture, fullpath);
#endif
                // texture already retained, no need to re-retain it
                _textures.insert( std::make_pair(fullpath, texture) );
            }
            else
            {
                CCLOG("cocos2d: Couldn't create texture for file:%s in TextureCache", path.c_str());
            }
        } while (0);
    }

    CC_SAFE_RELEASE(image);

    return texture;
}
/*..
省略
*/

 *outDataLen = dataLen/3*4;//将rgb的length增长到rgba的长度
 *outData = new unsigned char[*outDataLen];//申请一块长度为rgba长度的内存
 auto TempData=outData;
/*..
省略
*/
 for (ssize_t i = 0, j=0,l = dataLen - 2; i < l; i += 3,++j)
    {
        * outData ++ = data[i];         //R
        * outData ++ = data[i + 1];     //G
        * outData ++ = data[i + 2];     //B
        * outData ++ =png_data[j];      //A 依据灰度图的像素信息0和255设置alpha
    }
auto new_Texture2d=new Texture2D();
new_Texture2d->initWithData(TempData,datalen。pixelFormat, imageWidth, imageHeight, imageSize);


// so that we can achieve the main interface effect turret legendary.

For example, the main spring effect of light in the interface, is implemented by shader

As part of the bone dota is said to be their own flash engine to do, and I used to do a spine bones, bones due cocostuio function is not good, spine is designed specifically for bone editor. And the whole platform support, u3d, libgdx. as3 and so on.

The most praise should be the spine of ffd, the skin.

Right now is studying binary , that is spine binary file export. Directly read binary bone creation, it will more than json faster read. Smaller memory footprint.

ps: cocos2dx 3.1rc0 out, support prite3d and Video . Right now feeling video should be more useful, 3D , then personal feeling u3d it. . .

cocos of 3d support also need development.

Guess you like

Origin www.cnblogs.com/mqxnongmin/p/10972819.html
Recommended