1

我正在制作登录场景,但我不知道如何从文本字段中获取字符串值 谁能告诉我如何在用户输入时从输入文本字段中获取字符串数据 我已经使用 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));
     */
}
4

0 回答 0