cocos2d-x事件EventListenerTouchOneByOne沒反應


今天寫了 cocos2d-x事件EventListenerTouchOneByOne,發現死活沒反應,原代碼復制到新工程沒問題啊, 后來發現cocostudio用的基礎容器(ccui.Layout:create())默認是可交互性的,導出lua發現setTouchEnabled(true); 設置可觸摸是true,這就明了拉,是Layout(繼承Widget)擋住了事件下發了,按照cocos2d-x事件的原理看了C++源碼,發現:

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);
}
}
_touchListener->setSwallowTouches(true); 這句說明了一切。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM