我是cocos2d-x的新手。我在这行中出错:

Button* btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
btnRegister->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLoginTest, this));//get error no matching member function for call to addtoucheventlistener

我不知道为什么原因我已经在下面创建了一个构造函数
请帮助,我该怎么做才能解决该问题

文件LoginScene.h
#include "cocos2d.h"
#include "cocos-ext.h"
#include "CocosGUI.h"

USING_NS_CC;
USING_NS_CC_EXT;

using namespace ui;

class LoginScene : public Scene
{
public:
    LoginScene(bool pPortrait=false);
    ~LoginScene();
    // 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();

    virtual void onEnter();
    virtual void onExit();

    // a selector callback
    virtual void GameLogin();
    void GameLoginTest(Ref* pSender,TouchEventType type);
    //virtual void runThisTest()=0;
protected:

    Layer* m_pUILayer;
    Layout* m_pLayout;
    int authenticate();
    //int authenticate(const char* username, const char* password);
    // implement the "static create()" method manually
    //CREATE_FUNC(LoginScene);
};

文件LoginScene.cpp
#include "LoginScene.h"
#include "cocostudio/CCSSceneReader.h"
#include "cocostudio/CCSGUIReader.h"
#include "cocostudio/CCActionManagerEx.h"
#include "LoadingScene.h"
#include "MainScene.h"
#include "curl/curl.h"

LoginScene::LoginScene(bool pPortrait):m_pUILayer(NULL),m_pLayout(NULL)
{
    Scene::init();
}

LoginScene::~LoginScene()
{

}

void LoginScene::onEnter()
{
    Scene::onEnter();

    m_pUILayer=Layer::create();
    m_pUILayer->scheduleUpdate();
    this->addChild(m_pUILayer);

    m_pLayout=dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("LoginScene.json"));
    m_pUILayer->addChild(m_pLayout);

    Button* btnLogin = static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnLogin"));
    btnLogin->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLogin, this));//it's okay

    Button* btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
    btnRegister->addTouchEventListener(CC_CALLBACK_0(LoginScene::GameLoginTest, this));
    //get error no matching member function for call to addtoucheventlistener

}
void LoginScene::GameLogin()
{
    auto scene=LoadingScene::createScene();
    Director::getInstance()->pushScene(scene);
}

void LoginScene::GameLoginTest(Ref* pSender,TouchEventType type)
{
    if (type==TOUCH_EVENT_ENDED)
    {
        if (authenticate()==1)
        {
            auto scene=MainScene::createScene();
            Director::getInstance()->pushScene(TransitionFade::create(2.3f, scene));
        }
    }
}

最佳答案

对于LoginScene::GameLoginTest,也许您可​​以使用CC_CALLBACK_2,如下所示:
btnRegister-> addTouchEventListener(CC_CALLBACK_2(LoginScene::GameLoginTest,this));

关于c++ - C++错误没有匹配的成员函数可调用addtoucheventlistener,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25321375/

10-13 09:09