Cocos2dx:事件分发拦截
发布时间:2020-12-14 17:01:41 所属栏目:百科 来源:网络整理
导读:在加载cocostudio资源时,加载的节点在 rootNode - setVisible ( true ); 后使用拦截事件; //加载Cocos Studio编辑好的资源:卡片dialog auto rootNode = CSLoader::createNode("cardDialog.csb"); this-addChild(rootNode); rootNode-setVisible(false); ro
在加载cocostudio资源时,加载的节点在 rootNode->setVisible(true); 后使用拦截事件;
//加载Cocos Studio编辑好的资源:卡片dialog auto rootNode = CSLoader::createNode("cardDialog.csb"); this->addChild(rootNode); rootNode->setVisible(false); rootNode->setVisible(true); //拦截事件 auto callback = [](Touch *,Event *) { return true; }; auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = callback; touchListener->setSwallowTouches(true); //拦截本层事件 // 这里的触摸优先级设置为-128,与Menu同级,保证了屏蔽下方的触摸 _eventDispatcher->setPriority(touchListener,-128); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener,rootNode); touchListener->setSwallowTouches(false); //释放拦截本层事件 _eventDispatcher是Node的属性,通过它管理当前节点(如 场景、层、精灵等)的所有事件分发情况。但是它本身是一个单例模式的引用,在CCNode构造函数中,通过Director::getInstance()->getEventDispatcher()获取,有了这个属性,我们能更加方便的调用。</span> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |