您的位置:首页 > 移动开发 > Cocos引擎

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

2017-04-17 10:09 477 查看
原文地址: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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocos2dx 图片 color
相关文章推荐