需要给每个精灵设置tag.可以用枚举
bool GE::GamePass::ccTouchBegan( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
const int iButtonCount = 2;
const int iButtonTags[iButtonCount] = {
GamePass_btn_share,
GamePass_btn_return
};
for(int i = 0; i < iButtonCount; i++)
{
if(CCSprite* sprite = dynamic_cast<CCSprite*>(this->getChildByTag(iButtonTags[i])))
{
if(sprite->boundingBox().containsPoint(pTouch->getLocation()))
{
if(iButtonTags[i] == GamePass_btn_share)
{
//
}
else if(iButtonTags[i] == GamePass_btn_return)
{
GEMainScene::SetPageVisible(EGLT_GamePassLayer, false);
GEMainScene::SetPageVisible(EGLT_MainPageLayer, true);
}
return true;
}
}
}
return true;
}
时间: 2024-10-14 00:56:01