废话不说,直接比较2.x和3.0 final的代码,都是哪个eventlistener的问题:
2.x里面:
bool CCControl::init()
{
if (CCLayer::init())
{
//this->setTouchEnabled(true);
//m_bIsTouchEnabled=true;
// Initialise instance variables
m_eState=CCControlStateNormal;
setEnabled(true);
setSelected(false);
setHighlighted(false);
// Set the touch dispatcher priority by default to 1
this->setTouchPriority(1); //这里设定了CCControl(例如CCControlButton什么的)的touch优先级比正常的低一点
// Initialise the tables
m_pDispatchTable = new CCDictionary();
// Initialise the mapHandleOfControlEvents
m_mapHandleOfControlEvent.clear();
return true;
}
else
{
return false;
}
}
再来看3.0里面
bool Control::init()
{
if (Layer::init())
{
// Initialise instance variables
_state=Control::State::NORMAL;
setEnabled(true);
setSelected(false);
setHighlighted(false);
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->setSwallowTouches(true);
touchListener->onTouchBegan = CC_CALLBACK_2(Control::onTouchBegan, this);
touchListener->onTouchMoved = CC_CALLBACK_2(Control::onTouchMoved, this);
touchListener->onTouchEnded = CC_CALLBACK_2(Control::onTouchEnded, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(Control::onTouchCancelled, this);
dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); // 这里touchListener的优先级和缺省的一样,应该都是0
return true;
}
else
{
return false;
}
}
造成后果:
假设你在TableView的 Cell中加入CCControlButton或者什么东西,在2.x里面,因为CCControl的优先级较低,TableView可以正常处理touch事件进行拖动;但是在3.0里面,因为CCControl优先级同等且是子结点,touch事件被截获,到达不了TableView,于是你的啥可拖动列表统统完蛋。。。
我不知道这是by design还是咋的,但是很不方便,而且没有什么方便的方式去改变子Node的优先级??