1. 程式人生 > >Cocos2d-x 原生EditBox三種形式的使用

Cocos2d-x 原生EditBox三種形式的使用



包含標頭檔案

#include "ui\CocosGUI.h"
#include "cocos-ext.h"

USING_NS_CC;
USING_NS_CC_EXT;
using namespace ui;

auto glview = Director::getInstance()->getOpenGLView();
 auto visibleOrigin = glview->getVisibleOrigin();
 auto visibleSize = glview->getVisibleSize();
 Size size = Director::getInstance()->getVisibleSize();

//第一種 普通輸入

cocos2d::ui::Scale9Sprite* sacel9SprY = cocos2d::ui::Scale9Sprite::create("btn-play-selected.png");
 cocos2d::ui::EditBox* _editName = cocos2d::ui::EditBox::create(size / 2, sacel9SprY);
 _editName->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 2));
 _editName->setFontName("Paint Boy");
 _editName->setFontSize(25);
 _editName->setFontColor(Color3B::RED);
 _editName->setPlaceHolder("Name:");
 _editName->setPlaceholderFontColor(Color3B::WHITE);
 _editName->setMaxLength(8);
 _editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE);
 //_editName->setDelegate(this);
 addChild(_editName);


 //第二種 密碼輸入

 cocos2d::ui::Scale9Sprite* sacel9SprY = cocos2d::ui::Scale9Sprite::create("btn-play-selected.png");
 cocos2d::ui::EditBox* _editPassword = ui::EditBox::create(size / 2, sacel9SprY);
 _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);
 

//第三種 郵箱輸入
 cocos2d::ui::Scale9Sprite* sacel9SprY = cocos2d::ui::Scale9Sprite::create("btn-play-selected.png");
 cocos2d::ui::EditBox* _editEmail = ui::EditBox::create(Size(300, 60), sacel9SprY);
 _editEmail->setPosition(Vec2(visibleOrigin.x + visibleSize.width / 2, visibleOrigin.y + visibleSize.height / 4));
 _editEmail->setAnchorPoint(Vec2(0.5, 1.0f));
 _editEmail->setPlaceHolder("Email:");
 _editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS);
 //_editEmail->setDelegate(this);
 addChild(_editEmail);