cocos2dx 弹出模态窗口
弹出窗口触摸级别
layer3->setTouchPriority(kCCMenuHandlerPriority-1);//设置触摸级别 -128最高
layer3->setTouchMode(kCCTouchesOneByOne);
layer3->registerWithTouchDispatcher();//注册可以触摸
bool PauseInfo::init(int m_nSco,int level)
{
if (!CCLayer::init())
{
return false;
}
m_pPausedTargets = CCDirector::sharedDirector()->getScheduler()->pauseAllTargets();
CC_SAFE_RETAIN(m_pPausedTargets);
ccColor3B color = { 4, 4, 222};
mSize=CCDirector::sharedDirector()->getWinSize();
mBg= CCSprite::create("info/tishib.png");
mBg->setPosition(ccp(mSize.width / 2, mSize.height / 2));
this->addChild(mBg);
//返回
fhMenuItem = CCMenuItemImage::create(
"info/fanhui.png",
"info/fanhui.png",
this,
menu_selector(PauseInfo::fhOK));
fhMenuItem->setPosition(ccp(mSize.width / 2, mSize.height / 2+20));
fhMenuItem->setTag(level);
//退出
tcMenuItem = CCMenuItemImage::create(
"info/tuichu.png",
"info/tuichu.png",
this,
menu_selector(PauseInfo::tcOK));
tcMenuItem->setPosition(ccp(mSize.width / 2, mSize.height / 2-90));
tcMenuItem->setTag(level);
pMenu = CCMenu::create(fhMenuItem,tcMenuItem,NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu);
m_buttonArray=CCArray::create();
m_buttonArray->addObject(tcMenuItem);
m_buttonArray->addObject(fhMenuItem);
return true;
}
void PauseInfo::fhOK(CCObject* pSender )
{
CCDirector::sharedDirector()->getScheduler()->resumeTargets(m_pPausedTargets);
this->removeFromParentAndCleanup(true);
}
void PauseInfo::tcOK(CCObject* pSender )
{
CCDirector::sharedDirector()->end();
}
bool PauseInfo::ccTouchBegan(CCTouch *touch, CCEvent * pEvent)
{
// 因为拦截了所有消息(包括按钮) 所以需要将消息手动传给模态对话框上的按钮
if (pMenu) {
m_bTouchedControl = pMenu->ccTouchBegan(touch, pEvent);
}
return true;
}
void PauseInfo::ccTouchMoved(CCTouch *touch, CCEvent * pEvent)
{
if (m_bTouchedControl == true) {
pMenu->ccTouchMoved(touch, pEvent);
}
}
void PauseInfo::ccTouchEnded(CCTouch *touch, CCEvent * pEvent)
{
if (m_bTouchedControl == true) {
pMenu->ccTouchEnded(touch, pEvent);
}
}
void PauseInfo::ccTouchCancelled(CCTouch *touch, CCEvent * pEvent)
{
if (m_bTouchedControl == true) {
pMenu->ccTouchCancelled(touch, pEvent);
}
}
void PauseInfo::onExit(){
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
CCLayer::onExit();
};