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);

原文链接:https://www.f2er.com/cocos2dx/340291.html

猜你在找的Cocos2d-x相关文章