问题是EventListenerMouse的事件触发不了,EventListenerTouchOneByOne的getContentSize()宽高为0.帮忙看下。
_mybutton = ButtonSprite::create();
_mybutton->setName(“你好”);
addChild(_mybutton);
这样创建。
附件是代码。用得是cocos2dx 3.3
归档.zip (3 KB)
问题是EventListenerMouse的事件触发不了,EventListenerTouchOneByOne的getContentSize()宽高为0.帮忙看下。
_mybutton = ButtonSprite::create();
_mybutton->setName(“你好”);
addChild(_mybutton);
这样创建。
附件是代码。用得是cocos2dx 3.3
归档.zip (3 KB)
你代码里面只有触摸事件,没有鼠标响应事件,肯定没法触发啊…参考http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/event-dispatcher/zh.md
有啊,注释掉那几行。原先没注释时,也是不管用的。。
试过了正常响应,检查下你添加这个节点的时候是不是被其他的节点挡住了
还是不行 整个场景没有其他的的东西了。
还有
void ButtonSprite::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event)
{
CCLOG("%s",“onTouchEnded”);
cocos2d::Vec2 location=convertToNodeSpace(touch->getLocation());
cocos2d::Size size=this->getContentSize();
cocos2d::Rect rect=cocos2d::Rect(0,0,size.width,size.height);
if(rect.containsPoint(location)){
this->setScale(1);
}
}
getContentSize() width和height 是0 ,所以rect.containsPoint,也无法获取区域中的点。
你试试看吧…我就在空项目上测试你的代码的…