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);
实现弹出模态窗口摸管理的方法
最新推荐文章于 2023-11-30 14:26:11 发布