Cocos2dx/EditBox
提供: 初心者エンジニアの簡易メモ
EditBoxとは
入力欄のこと
サンプル
HelloworldScene.h
#include "ui/CocosGUI.h" class HelloWorld : public cocos2d::Layer, cocos2d::ui::EditBoxDelegate { public: static cocos2d::Scene* createScene(); virtual bool init(); CREATE_FUNC(HelloWorld); private: virtual void editBoxEditingDidBegin(cocos2d::ui::EditBox* editBox); virtual void editBoxEditingDidEnd(cocos2d::ui::EditBox* editBox); virtual void editBoxTextChanged(cocos2d::ui::EditBox* editBox, const std::string& text); virtual void editBoxReturn(cocos2d::ui::EditBox* editBox); };
HelloworldScene.cpp
bool HelloWorld::init() { // 略 cocos2d::ui::EditBox* _editPassword = ui::EditBox::create(editBoxSize, "extensions/orange_edit.png"); _editPassword->setPosition(Vec2(visibleOrigin.x+visibleSize.width/2, visibleOrigin.y+visibleSize.height/2)); _editPassword->setFont("American Typewriter", 80); _editPassword->setFontColor(Color3B::GREEN); _editPassword->setPlaceHolder("Password:"); _editPassword->setMaxLength(6); _editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD); _editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); _editPassword->setDelegate(this); addChild(_editPassword); return true; } void Helloworld::editBoxEditingDidBegin(EditBox *editBox) { } void Helloworld::editBoxEditingDidEnd(EditBox *editBox) { } void Helloworld::editBoxTextChanged(EditBox *editBox, const std::string& text) { } void Helloworld::editBoxReturn(EditBox *editBox) { }
Extensionは非推奨
cocos2d-x ui::EditBoxを使う