.h里边是这样的
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
//#include "cocos-ext.h"
USING_NS_CC;
using namespace cocos2d::ui;
//USING_NS_CC_EXT;
class HelloWorld : public cocos2d::Layer
{
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// a selector callback
void menuCloseCallback(cocos2d::Ref* pSender);
void touchDown(Ref* pSender, Widget::TouchEventType type);
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__
```
.cpp里主要那一块是这样的
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
auto rootNode = CSLoader::createNode("MainScene.csb");
addChild(rootNode);
auto panel_title = rootNode->getChildByTag(1);
auto btn_menu = static_cast(rootNode->getChildByTag(2));
btn_menu->addTouchEventListener(this, SEL_TouchEvent(&HelloWorld::menuCloseCallback));
return true;
}
void HelloWorld::touchDown(Ref* pSender,Widget::TouchEventType type)
{
switch (type)
{
case ui::Widget::TouchEventType::BEGAN:
break;
case ui::Widget::TouchEventType::ENDED:
break;
case ui::Widget::TouchEventType::MOVED:
break;
default:
break;
}
CCLOG("touch menu");
}
```
然后运行就报这个错
1>c:\workspace\cocos2dx\cocos2dx_workspace\cocos\cocosprojects\smarttvcocos\classes\helloworldscene.cpp(46): error C2511: “void HelloWorld::touchDown(cocos2d::Ref *,cocos2d::ui::Widget::TouchEventType)”:“HelloWorld”中没有找到重载的成员函数
1> c:\workspace\cocos2dx\cocos2dx_workspace\cocos\cocosprojects\smarttvcocos\classes\helloworldscene.h(12) : 参见“HelloWorld”的声明
我这个应该是声明了吧,在下超级小白,求大神帮助。
运行环境
win8.1+64位+vs2013+cocos2d-x 3.3RC0 + cocosStudio 2.0