当用户在cocos2d-x中输入时,如何从输入文本字段获取字符串数据

时间:2014-08-20 09:58:58

标签: c++ ios cocos2d-x cocos2d-x-3.0 cocostudio

我正在制作一个登录场景,但我不知道如何从文本字段中获取getstringvalue 任何人都可以告诉我如何在用户输入时从输入文本字段获取字符串数据 我已经用cocostudio创建了这样的布局: 我试过std:string userinput = txtUsername-> getStringValue()。c_str()但没有运气:(

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

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

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

    //button initialize
    Button *btnLogin=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnLogin"));
    btnLogin->addTouchEventListener(CC_CALLBACK_2(LoginScene::onLogin, this));

    Button *btnRegister=static_cast<Button*>(Helper::seekWidgetByName(m_pLayout, "btnRegister"));
    btnRegister->addTouchEventListener(CC_CALLBACK_2(LoginScene::onRegister, this));

    //textfield initialize
    TextField *txtUsername=static_cast<TextField*>(Helper::seekWidgetByName(m_pLayout, "txtUsername"));
    txtUsername->addEventListenerTextField(m_pLayout, textfieldeventselector(LoginScene::TextFieldEvent));

    TextField *txtPassword=static_cast<TextField*>(Helper::seekWidgetByName(m_pLayout, "txtPassword"));
    txtPassword->addEventListenerTextField(m_pLayout, textfieldeventselector(LoginScene::TextFieldEvent));
    /*
    //checkbox initialize
    CheckBox* checkbox = static_cast<CheckBox*>(Helper::seekWidgetByName(m_pLayout, "checkbox"));
    checkbox->addEventListenerCheckBox(m_pLayout, checkboxselectedeventselector(LoginScene::selectedStateEvent));
     */
}

0 个答案:

没有答案