我有两个Layer,1是背景层,2是UI层,加入顺序是1,2,
然后我想用触摸方式移动1背景层的图片,但移动不了,查了些资料,以下是我的设置
在UI层的onEnter()我这样设置:
setTouchEnabled(true);
touchListener->setSwallowTouches(false);
touchListener->onTouchBegan = CC_CALLBACK_2(GamePlayScene::onTouchBegan, this); 返回了false
touchListener->onTouchMoved = CC_CALLBACK_2(GamePlayScene::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(GamePlayScene::onTouchEnded, this);
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addEventListenerWithSceneGraphPriority(touchListener,this);
在地图背景层的onEnter()我这样设置:
this->setTouchEnabled(true);
touchListener->setSwallowTouches(false);
touchListener->onTouchBegan = CC_CALLBACK_2(GamePlayScene::onTouchBegan, this);返回了false
touchListener->onTouchMoved = CC_CALLBACK_2(GamePlayScene::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(GamePlayScene::onTouchEnded, this);
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->addEventListenerWithSceneGraphPriority(touchListener,this);
然后两个层加入到场景中
pScene->addChild(pMapLayer,10);
pScene->addChild(m_pMainMenuLayer,20);
最后没有作用,依旧无法移动背景层!