zoukankan      html  css  js  c++  java
  • 关于cocos2d-x精灵加亮及变灰效果

    //根据现有CCSprite,变亮和变灰
    static CCSprite* graylightWithCCSprite(CCSprite* oldSprite,bool isLight)
    {
        //CCSprite转成CCimage
        CCPoint p = oldSprite->getAnchorPoint();
        oldSprite->setAnchorPoint(ccp(0,0));
        CCRenderTexture *outTexture = CCRenderTexture::create((int)oldSprite->getContentSize().width,(int)oldSprite->getContentSize().height);
        outTexture->begin();
        oldSprite->visit();
        outTexture->end();
        oldSprite->setAnchorPoint(p);
        
        CCImage* finalImage = outTexture->newCCImage();
        unsigned char *pData = finalImage->getData();
        int iIndex = 0;
        
        if(isLight)
        {
            for (int i = 0; i < finalImage->getHeight(); i ++)
            {
                for (int j = 0; j < finalImage->getWidth(); j ++)
                {
                    // highlight
                    int iHightlightPlus = 50;
                    int iBPos = iIndex;
                    unsigned int iB = pData[iIndex];
                    iIndex ++;
                    unsigned int iG = pData[iIndex];
                    iIndex ++;
                    unsigned int iR = pData[iIndex];
                    iIndex ++;
                    //unsigned int o = pData[iIndex];
                    iIndex ++;  //原来的示例缺少
                    iB = (iB + iHightlightPlus > 255 ? 255 : iB + iHightlightPlus);
                    iG = (iG + iHightlightPlus > 255 ? 255 : iG + iHightlightPlus);
                    iR = (iR + iHightlightPlus > 255 ? 255 : iR + iHightlightPlus);
                    //            iR = (iR < 0 ? 0 : iR);
                    //            iG = (iG < 0 ? 0 : iG);
                    //            iB = (iB < 0 ? 0 : iB);
                    pData[iBPos] = (unsigned char)iB;
                    pData[iBPos + 1] = (unsigned char)iG;
                    pData[iBPos + 2] = (unsigned char)iR;
                }
            }
        }else{
            for (int i = 0; i < finalImage->getHeight(); i ++)
            {
                for (int j = 0; j < finalImage->getWidth(); j ++)
                {
                    // gray
                    int iBPos = iIndex;
                    unsigned int iB = pData[iIndex];
                    iIndex ++;
                    unsigned int iG = pData[iIndex];
                    iIndex ++;
                    unsigned int iR = pData[iIndex];
                    iIndex ++;
                    //unsigned int o = pData[iIndex];
                    iIndex ++; //原来的示例缺少
                    unsigned int iGray = 0.3 * iR + 0.4 * iG + 0.2 * iB;
                    pData[iBPos] = pData[iBPos + 1] = pData[iBPos + 2] = (unsigned char)iGray;
                }
            }
        }
        
        CCTexture2D *texture = new CCTexture2D;
        texture->initWithImage(finalImage);
        CCSprite* newSprite = CCSprite::createWithTexture(texture);
        delete finalImage;
        texture->release();
        return newSprite;
    }

    http://blog.csdn.net/chenli0741/article/details/8860036

    在这个博客提供的png图片alpha通道的精灵变灰与变亮的。

    但是,在变灰的时候,如果图片是有红色的话,则会出现不同的效果,不是叠加,而图片直接变灰。

    可以看出,第二种情况,不是叠加上去的,而是把图片都变灰了。由于不怎么熟悉ARGB,还未解决的办法。

  • 相关阅读:
    Jquery仿百度经验左右滚动切换效果(转)
    MySql之左连接,右连接
    MYSQL之IFNULL
    阿里云的云盘挂载
    Discuz管理员前台正常后台登录不进如何解决
    改善用户体验之wordpress添加图片弹出层效果 (插件 FancyBox)
    PHP session有效期session.gc_maxlifetime的设置方法
    Linux下php安装Redis扩展
    sequel 连接不上,命令行能连上
    mysql远程连接命令
  • 原文地址:https://www.cnblogs.com/yuan19/p/3280089.html
Copyright © 2011-2022 走看看