CCSprite* CCSpotlight::makeSpiteGray(CCSprite* changeSprite){ CCRenderTexture *render = CCRenderTexture::create(changeSprite->getContentSize().wIDth,changeSprite->getContentSize().height,kCCTexture2DPixelFormat_RGBA8888); render->beginWithClear(0.0f,0.0f,0.0f); changeSprite->visit(); render->end(); //CCDirector::getInstance()->getRenderer()->render(); CCImage *finalimage = render->newCCImage(); unsigned char *pData = finalimage->getData(); int iIndex = 0; for (int i = 0; i < finalimage->getHeight(); i ++) { if (i >= 100 && i < 200) continue; for (int j = 0; j < finalimage->getWIDth(); j ++) { if (j >= 50 && j < 100) continue; // gray int iBPos = iIndex; unsigned int iB = pData[iIndex]; iIndex ++; unsigned int iG = pData[iIndex]; iIndex ++; unsigned int iR = pData[iIndex]; iIndex ++; iIndex ++; unsigned int iGray = 0.3 * iR + 0.6 * iG + 0.1 * iB; pData[iBPos] = pData[iBPos + 1] = pData[iBPos + 2] = (unsigned char)iGray; } } CCTexture2D *texture = new CCTexture2D; texture->initWithImage(finalimage); auto pSprite = CCSprite::createWithTexture(texture); delete finalimage; texture->release(); return pSprite;}总结
以上是内存溢出为你收集整理的Cocos-2dx精灵部分变灰全部内容,希望文章能够帮你解决Cocos-2dx精灵部分变灰所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)