C++ cocos2d-x带图层的触摸处理
我对cocos2d-x触摸处理器有问题。我有两节课。每个类都有一个场景和一个层。我在两个层上都有精灵,它们在同一个函数中处理。问题是当我从A层过渡到B层并点击精灵时,触摸处理程序从A层获取精灵,但我需要B层的精灵,很明显我点击了B层。据我所知,问题在于setPriority?你能帮我解决这个问题吗?谢谢 卡迪姆是我的精灵C++ cocos2d-x带图层的触摸处理,c++,touch,cocos2d-x,layer,cocos2d-x-3.0,C++,Touch,Cocos2d X,Layer,Cocos2d X 3.0,我对cocos2d-x触摸处理器有问题。我有两节课。每个类都有一个场景和一个层。我在两个层上都有精灵,它们在同一个函数中处理。问题是当我从A层过渡到B层并点击精灵时,触摸处理程序从A层获取精灵,但我需要B层的精灵,很明显我点击了B层。据我所知,问题在于setPriority?你能帮我解决这个问题吗?谢谢 卡迪姆是我的精灵 void CardItem::addEvents() { auto listener = cocos2d::EventListenerTouchOneByOne::cr
void CardItem::addEvents()
{
auto listener = cocos2d::EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event)
{
cocos2d::Vec2 p = touch->getLocation();
cocos2d::Rect rect = this->getBoundingBox();
if(rect.containsPoint(p))
{
return true; // to indicate that we have consumed it.
}
return false; // we did not consume this event, pass thru.
};
listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event)
{
//I have here some code
};
cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 30);
}
void CardItem::touchEvent(cocos2d::Touch* touch, cocos2d::Vec2 _point)
{
auto *pNode = this->getParent(); // here is "pNode" always gets layer A
}
这就是我在A层和B层之间改变场景的方式
void GameBoardLayer::showGameBoardComputer()
{
pGameBoardComputerScene = GameBoardComputerScene::create();
auto pGameBoardComputerLayer = pGameBoardComputerScene->getLayer();
Director::getInstance()->pushScene(pGameBoardComputerScene);
}
void GameBoardComputerLayer::gameBoardComputerItemBackCallback(Ref* pSender)
{
Director::getInstance()->popScene();
}
因此,当我单击sprite时,无论它是哪一层,它总是通过层B单击层A发布代码的相关部分