cocos2dx 弹出模态窗口

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();
};

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值