不规则按钮(3.2版)哪位大大指点一下,不胜感激!

今天突然发现用2.0时代重绘方式处理不规则按钮响应的已经无效了。
原因3.0时代异步方式重绘了,
怎么高效的过滤透明区域响应?

bool Widget::onTouchBegan(Touch touch, Event unusedEvent)
{
_hitted = false;
if (isVisible() && isEnabled() && isAncestorsEnabled() && isAncestorsVisible(this) )
{
_touchBeganPosition = touch->getLocation();
if(hitTest(_touchBeganPosition) && isClippingParentContainsPoint(_touchBeganPosition))
{
_hitted = true;
}
}
if (!_hitted)
{
return false;
}
if(_realTouchRange)
{
Node
target = static_cast<Node
>(unusedEvent->getCurrentTarget());
std::string strField = target->getName();
//Vec2 touchPoint = target->convertTouchToNodeSpaceAR(touch);
Vec2 touchPoint = target ->convertToNodeSpace(touch->getLocation());
Size s = target ->getContentSize();
RenderTexture* renderTexture = RenderTexture::create(target->getContentSize().width, target->getContentSize().height, Texture2D::PixelFormat::RGBA8888);
uint8_t data;
//RenderTexture* renderTexture = RenderTexture::create(1* CC_CONTENT_SCALE_FACTOR(),1 * CC_CONTENT_SCALE_FACTOR(), Texture2D::PixelFormat::RGBA8888);

renderTexture->beginWithClear(0,0,0,0);
//只保存渲染一个像素的数据
Vec2 oldPos = target->getPosition();
Vec2 oldAnchor = target->getAnchorPoint();
target->setAnchorPoint(Vec2::ZERO);
//target->setPosition(Vec2(-touchPoint.x * CC_CONTENT_SCALE_FACTOR(), -touchPoint.y * CC_CONTENT_SCALE_FACTOR()));
target->visit();
target->setAnchorPoint(oldAnchor);
target->setPosition(oldPos);
renderTexture->end();
Renderer* renderer = Director::getInstance()->getRenderer();
//Director::getInstance()->getRenderer()->render();
renderer->render();
Image * pImage = renderTexture->newImage();
//Color4B c = pImage->getColor4B(point.x, point.y);
//获取像素数据
unsigned char* data_ = pImage->getData();
unsigned int *pixel = (unsigned int *)data_;
Color4B c;
//R通道
c.r = *pixel & 0xff;
//G通道
c.g = (*pixel >> 8) & 0xff;
//B通过
c.b = (*pixel >> 16) & 0xff;
//Alpha通道,我们有用的就是Alpha
c.a = (pixel >> 24) & 0xff;
if(c.a < 50)
{
return false;
}
}
setHighlighted(true);
Widget
widgetParent = getWidgetParent();
if (widgetParent)
{
widgetParent->interceptTouchEvent(TouchEventType::BEGAN, this, touch);
}
pushDownEvent();
return true;
}

up~~~~~~~~~~~~

按一位大大说法,3.0需要增加Director::getInstance()->getRenderer()->render();

在renderTexture->end();后
Image * pImage = renderTexture->newImage();前

测试后,还是无效

今天试了glreadpixel也不行,全是-1

if(p1.containsPoint§)
{
int8_t data;
Point touchPoint = node->convertTouchToNodeSpace(touch);
Point location = Point((touchPoint.x) * CC_CONTENT_SCALE_FACTOR(), (touchPoint.y) * CC_CONTENT_SCALE_FACTOR());
RenderTexture* renderTexture = RenderTexture::create(1* CC_CONTENT_SCALE_FACTOR(),1 * CC_CONTENT_SCALE_FACTOR(), Texture2D::PixelFormat::RGBA8888);
renderTexture->beginWithClear(0,0,0,0);
//只保存渲染一个像素的数据
Point oldPos = node->getPosition();
Point oldAnchor = node->getAnchorPoint();
node->setAnchorPoint(Point(0,0));
node->setPosition(Point(-location.x, -location.y));
node->visit();
node->setAnchorPoint(oldAnchor);
node->setPosition(oldPos);
glReadPixels(0,0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
renderTexture->end();
renderTexture->release();
//检测alpha值
CCLOG(“X:.0f y:.0f R: %d, G: %d, B: %d, A: %d tag:%d”,location.x ,location.y, data, data, data, data,this->getTag());
if(data || data || data || data)
{
CCLOG(“非透明”);
}
else
{
CCLOG(“透明”);
}
}

尝试一下另外一种方案:
按不规则按钮形状,记录了一组节点,组成一个不规则框,
然后写个小算法,判断点击坐标是否在不规则框中。
设计模式下一切OK,
但在其他分辨率下错位了~~~~~~~~~~~~~~
有啥改进办法?