首页 > 其他 > 详细

cocos2d-x纹理去色

时间:2014-06-29 07:36:43      阅读:375      评论:0      收藏:0      [点我收藏+]

    //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;

    

    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 = newCCTexture2D;

    texture->initWithImage(finalImage);

    CCSprite* newSprite = CCSprite::createWithTexture(texture);

    delete finalImage;

    texture->release();

    

    return newSprite;

cocos2d-x纹理去色,布布扣,bubuko.com

cocos2d-x纹理去色

原文:http://www.cnblogs.com/sealme/p/3770110.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!