我创建了一个Button,代码如下:
btnGetGold = Button::create(“Shop/plus.png”,“Shop/plus_press.png”);
btnGetGold->addTouchEventListener(this,toucheventselector(ShopLayer::btnCallback));
但是点击没有反应,在查看3.2引擎自带示例的时候,看到了如下代码:(文件路径:D:\cocos2d-x-3.2\tests\cpp-tests\Classes\UITest\CocoStudioGUITest\UIButtonTest)
Button* button = Button::create(“cocosui/animationbuttonnormal.png”, “cocosui/animationbuttonpressed.png”);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
// button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest::touchEvent, this));
_uiLayer->addChild(button);
我看到这里注释掉了原来2.x中的添加触摸监听器的方法,于是也学着这样创建了一个Button,结果在addTouchEventListener的时候使用了CC_CALLBACK_2提示参数过少,跳到addTouchEventListener原函数查看并没有重载相关的参数,
然后我对比了引擎中和我自己创建的工程中的如下文件:D:\cocos2d-x-3.2\cocos\ui\UIWidget.cpp,发现两者大不相同,难道工程中的文件不是从引擎中拷贝的么?
在3.2中到底应该怎样使用Button呢?
