检查按钮透明部分
bool CCMenu::CheckAlphaPoint(CCMenuItem* pChild, const CCPoint& point)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCNode* selectSprite = ((CCMenuItemSprite*)pChild)->getSelectedImage();
CCRenderTexture *renderer = CCRenderTexture::create(winSize.width, winSize.height);
renderer->begin();
bool visible = selectSprite->isVisible();
if (visible) {
selectSprite->visit();
}
else
{
selectSprite->setVisible(true);
selectSprite->visit();
selectSprite->setVisible(false);
}
GLubyte pixelColors[4];
glReadPixels(point.x, point.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelColors[0]);
glReadPixels(point.x, point.y, 1, 1, GL_ALPHA, GL_UNSIGNED_BYTE, &pixelColors[0]);
int alpha = pixelColors[0];
CCLOG(----alpha %d, alpha);
renderer->end();
if (alpha <= 30)
{
return true;
}
else
{
return false;
}
}
创建一个按钮
bool Logo::init()
{
if(!Layer::init())
return false;
auto logo = ECommonBg::createBg("cover.png");
addChild(logo);
auto btn = cocos2d::ui::Button::create("start_game.png","start_game.png");
btn->setPosition(Vec2(WIN_WIDTH/2, WIN_HEIGHT* 0.3));
btn->addTouchEventListener(this, toucheventselector(Logo::callBack));
this->addChild(btn,4);
return true;
}
void Logo::callBack(Ref* sender, TouchEventType b)
{
log("callBack Called!~");
}