Cocos2dx图片像素颜色值获取,可用于判断是否是图片的透明区域

原文地址:http://blog.csdn.net/qipa_game/article/details/38116805

Color4B Sprite::getPixelColor(const Vec2& pos)
{
int8_t data[4];
Vec2 oldPos = this->getPosition();
Vec2 oldAnchor = this->getAnchorPoint();
RenderTexture* pRender = RenderTexture::create(1, 1, Texture2D::PixelFormat::RGBA8888);
pRender->beginWithClear(0, 0, 0, 0);
this->setAnchorPoint(Vec2::ZERO);
this->setPosition(-pos.x, -pos.y);
this->visit();
this->setAnchorPoint(oldAnchor);
this->setPosition(oldPos);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
pRender->end();
Color4B color(data[0], data[1], data[2], data[3]);
return color;
}


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页