facebook twitter hatena line email

「Cocos2dx/EditBox」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(他色々ある)
(他色々ある)
 
(同じ利用者による、間の1版が非表示)
行77: 行77:
 
ANY
 
ANY
 
The user is allowed to enter any text, including line breaks.
 
The user is allowed to enter any text, including line breaks.
日本語&改行も含む
+
日本語OK&改行も含む
  
 
EMAIL_ADDRESS
 
EMAIL_ADDRESS
行94: 行94:
 
DECIMAL
 
DECIMAL
 
The user is allowed to enter a real number value.
 
The user is allowed to enter a real number value.
 
 
This extends kEditBoxInputModeNumeric by allowing a decimal point.
 
This extends kEditBoxInputModeNumeric by allowing a decimal point.
 +
端末によってはカンマなどを許容する?(確認した端末ではカンマ入力できなかった。上のNUMERICと同じ?)
  
 
SINGLE_LINE
 
SINGLE_LINE
 
The user is allowed to enter any text, except for line breaks.
 
The user is allowed to enter any text, except for line breaks.
 +
日本語OKで、改行不可
 
</pre>
 
</pre>
  

2018年12月4日 (火) 10:40時点における最新版

EditBoxとは

入力欄のこと

サンプル

cocos2d::ui::EditBox* _editPassword = ui::EditBox::create(Size(visibleSize.width/3, 30), "extensions/orange_edit.png");
_editPassword->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
_editPassword->setFont("American Typewriter", 16);
_editPassword->setFontColor(Color3B::GREEN);
_editPassword->setPlaceHolder("Password:");
_editPassword->setMaxLength(6);
_editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD);
_editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE);
_editPassword->setText("初期文字");
addChild(_editPassword);

文字取得

_editPassword->getText();

イベント付きサンプル

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

USING_NS_CC;
using namespace ui;
// 略
bool HelloWorld::init()
{
// 略
    cocos2d::ui::EditBox* _editPassword = ui::EditBox::create(Size(visibleSize.width/3, 30), "extensions/orange_edit.png");
    _editPassword->setPosition(Vec2(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
    _editPassword->setFont("American Typewriter", 16);
    _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) {
}

参考:http://falstar.hateblo.jp/entry/2016/07/18/213355

イベントを取得したいときのみEditBoxDelegateとsetDelegate(this)を追加する

Extensionは非推奨

cocos2d-x ui::EditBoxを使う

http://falstar.hateblo.jp/entry/2016/07/18/213355

数字のみに限定する

setInputMode(EditBox::InputMode::NUMERIC);


他色々ある

ANY 	
The user is allowed to enter any text, including line breaks.
日本語OK&改行も含む

EMAIL_ADDRESS 	
The user is allowed to enter an e-mail address.

NUMERIC 	
The user is allowed to enter an integer value.
端末によってはカンマなどを許容する

PHONE_NUMBER 	
The user is allowed to enter a phone number.

URL 	
The user is allowed to enter a URL.

DECIMAL 	
The user is allowed to enter a real number value.
This extends kEditBoxInputModeNumeric by allowing a decimal point.
端末によってはカンマなどを許容する?(確認した端末ではカンマ入力できなかった。上のNUMERICと同じ?)

SINGLE_LINE 	
The user is allowed to enter any text, except for line breaks.
日本語OKで、改行不可


http://www.cocos2d-x.org/reference/native-cpp/V3.10/dd/df1/group__ui.html#ga4b759aa0169566a8ff6a20313da6a580

libMyGame.so エラーが出る場合

cocos2dx-3.17でEditBoxを使って以下エラーがでる場合、Resourcesに指定した画像ファイルがあるか確認する

/data/app/jp.co・・・・/lib/arm/libMyGame.so 

(_ZN7cocos2d2ui7EditBox6createERKNS_4SizeEPNS0_12Scale9SpriteES6_S6_+168)