现在做个项目,使用的是quick3.3final+cocosstudio2.06来做UI
发现cocosstudio使用的是cocos2d_libs下的ui.widgets下的控件
而lua层又有一套ui在framework.cc.ui下
问题1:这两套UI是什么关系?
在一个界面当中,我分别使用了cocosstudio中的控件和uipushbutton来拼成的
但是uipushbutton接受不到touch事件,貌似都被cocosstudio生成的button吃掉了
查看源代码,发现uipushbutton注册touch事件监听最终会因为setTouchEnabled方法然后调用到
void LuaTouchEventManager::enableTouchDispatching()
{
if (!_touchListener)
{
_touchListener = EventListenerTouchAllAtOnce::create();
if (!_touchListener) {
return;
}
_touchListener->onTouchesBegan = CC_CALLBACK_2(LuaTouchEventManager::onTouchesBegan, this);
_touchListener->onTouchesMoved = CC_CALLBACK_2(LuaTouchEventManager::onTouchesMoved, this);
_touchListener->onTouchesEnded = CC_CALLBACK_2(LuaTouchEventManager::onTouchesEnded, this);
_touchListener->onTouchesCancelled = CC_CALLBACK_2(LuaTouchEventManager::onTouchesCancelled, this);
_eventDispatcher->addEventListenerWithFixedPriority(_touchListener, -1);
}
m_touchDispatchingEnabled = true;
}
这样子的话在touch事件分发EventDispatcher的dispatchTouchEvent时会被EventListenerTouchOneByOne的事件截掉
而cocosstudio生成的button通过 Widget的setTouchEnabled
void Widget::setTouchEnabled(bool enable)
{
if (enable == _touchEnabled)
{
return;
}
_touchEnabled = enable;
if (_touchEnabled)
{
_touchListener = EventListenerTouchOneByOne::create();
CC_SAFE_RETAIN(_touchListener);
_touchListener->setSwallowTouches(true);
_touchListener->onTouchBegan = CC_CALLBACK_2(Widget::onTouchBegan, this);
_touchListener->onTouchMoved = CC_CALLBACK_2(Widget::onTouchMoved, this);
_touchListener->onTouchEnded = CC_CALLBACK_2(Widget::onTouchEnded, this);
_touchListener->onTouchCancelled = CC_CALLBACK_2(Widget::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(_touchListener, this);
}
else
{
_eventDispatcher->removeEventListener(_touchListener);
CC_SAFE_RELEASE_NULL(_touchListener);
}
}
这样子如果cocosstudio和lua的ui混用的话lua的ui就获取不到touch事件了。
问题2:我这个理解是对的么?
问题3:quick编程当中是希望开发人员使用哪套UI呢?