<span style="font-family: Menlo; background-color: rgb(255, 255, 255);">在init方法中添加如下的代码,实现文本输入</span>
auto getname = TextFieldTTF::textFieldWithPlaceHolder("[在这里输入你的名字]", "楷体", 40);
getname->setPosition(size.width/2, size.height/2);
this->addChild(getname);
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [getname](Touch* ptouch,Event* event){
if (getname->boundingBox().containsPoint(ptouch->getLocation())) {
getname->attachWithIME();
}
else
getname->detachWithIME();
return false;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, getname);
如何保存输入进来的数据?
<pre name="code" class="cpp" style="font-size: 11px; color: rgb(53, 86, 138);">std::string a;
a = getname->getString();
<span style="font-family: Menlo;">log("%s",a.c_str());</span>