实现弹出模态窗口摸管理的方法

1.创建commomLayer::public CCLayer


2.实现函数
virtual bool init();
bool CJYPopLayer::init()
{
    //
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    _alph = 140;
    setKeypadEnabled(true);
    this->setTouchEnabled(true);
    return true;
}

virtual void onEnter();
void CJYPopLayer::onEnter(){
    CCLayer::onEnter();
    CCLayerColor *pBgLayer = CCLayerColor::create(ccc4(1, 1, 1, _alph));
    addChild(pBgLayer,0);
}

virtual void onExit();
void CJYPopLayer::onExit(){
    CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
    CCLayer::onExit();
    
}

virtual void registerWithTouchDispatcher(void);
void CJYPopLayer::registerWithTouchDispatcher(void){
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true);
    
}

virtual bool ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event);
bool CJYPopLayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event){
    return true;
}

virtual void menuCloseCallback(CCObject* pSender);
void CJYPopLayer::menuCloseCallback(CCObject* pSender)
{
   this->removeFromParentAndCleanup(true);
}

virtual void keyBackClicked();
void CJYPopLayer::keyBackClicked() {


	this->removeFromParent();
}


3.在继承中调用父类
void CJYSettingScene::onEnter()
{
    CJYPopLayer::onEnter();
}

void CJYSettingScene::onExit()
{
    CJYPopLayer::onExit();
}


CCMenuItemImage *closeBtn= CCMenuItemImage::create("Setting/closeBtn_n.png", "Setting/closeBtn_s.png", this, menu_selector(CJYPopLayer::menuCloseCallback));


4.主场景中调用该弹框
CJYSettingScene *pScene = CJYSettingScene::create();
pScene->setTouchPriority(-1100);
pScene->setAlph(99);//mvc分离,数值在onEnter中实现
addChild(pScene);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值