gpt4 book ai didi

C++ 错误 No matching member function for call to addtoucheventlistener

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:52:54 34 4
gpt4 key购买 nike

我是 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++ 错误 No matching member function for call to addtoucheventlistener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25321375/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com