原文地址: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;
}