码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x纹理去色

时间:2014-06-29 07:46:41      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:style   get   width   os   for   c   

    //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纹理去色

标签:style   get   width   os   for   c   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!