首页 > 其他 > 详细

cocos2d-x事件EventListenerTouchOneByOne没反应

时间:2016-12-31 16:48:04      阅读:296      评论:0      收藏:0      [点我收藏+]

今天写了 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); 这句说明了一切。

cocos2d-x事件EventListenerTouchOneByOne没反应

原文:http://www.cnblogs.com/qianwang/p/6239409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!