티스토리 뷰
HelloWorldScene.h
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" #include "cocostudio/CocoStudio.h" #include "ui\UIEditBox\UIEditBox.h" #include "ui/CocosGUI.h" USING_NS_CC; using namespace ui; class HelloWorld : public cocos2d::Layer, EditBoxDelegate { public: // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); // a selector callback void menuCloseCallback(cocos2d::Ref* pSender); // implement the "static create()" method manually CREATE_FUNC(HelloWorld); EditBox* eb_first; //First EditBox EditBox* eb_second; //Second EditBox void editbox_Callback(EditBox* editBox); //Custom Function virtual void editBoxEditingDidBegin(EditBox* editBox); virtual void editBoxEditingDidEnd(EditBox* editBox); virtual void editBoxTextChanged(EditBox* editBox, const std::string& text); virtual void editBoxReturn(EditBox* editBox); }; #endif // __HELLOWORLD_SCENE_H__
HelloWorldScene.cpp
#include "HelloWorldScene.h" Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } auto rootNode = CSLoader::createNode("HelooWorldScene.csb"); addChild(rootNode); ///////////////////////////////////////First EditBox/////////////////////////////////////// eb_first = EditBox::create(Size(150, 50), Scale9Sprite::create("YourPic.png")); eb_first->setAnchorPoint(Vec2(0, 0.5f)); eb_first->setPosition(Vec2(50, 100)); eb_first->setReturnType(ui::EditBox::KeyboardReturnType::NEXT); //Return Button Change(Next) eb_first->setDelegate(this); addChild(eb_first); /////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////Second EditBox/////////////////////////////////////// eb_second = EditBox::create(Size(150, 50), Scale9Sprite::create("YourPic.png")); eb_second->setAnchorPoint(Vec2(0, 0.5f)); eb_second->setPosition(Vec2(250, 100)); eb_second->setReturnType(ui::EditBox::KeyboardReturnType::DONE); //Return Button Change(Done) eb_second->setDelegate(this); addChild(eb_second); /////////////////////////////////////////////////////////////////////////////////////////////// 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) { //the function when touched Return button. if (editBox == eb_first) { CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(HelloWorld::editbox_Callback, this, eb_second)); this->runAction(Sequence::create(DelayTime::create(0.15f), runCallback, nullptr)); //0.15 second Delay -> runCallback } } void HelloWorld::editbox_Callback(EditBox* editBox) { editBox->touchDownAction(editBox, Widget::TouchEventType::ENDED); //eb_second get focus and show keyboard like eb_second has touched. }
I Made 2 EditBoxes.
when First EditBox Input finished and touched Return Button,
Second EditBox will have focus and show keyboard.
When i didn't put Delay, it didn't show keyboard or had focus bug.
I tested on Android.
'Cocos2d-x' 카테고리의 다른 글
cocos2d-x. Solution for low FPS on Android (0) | 2016.05.21 |
---|
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Galaxy
- focus
- rate
- FPS
- Keyboard
- AppDelegate
- Solution
- source
- editbox
- How
- low
- 58
- cocos2d-x
- Media
- 40
- Samsung
- How to
- PHONE
- YouTube
- android
- Download
- Downloader
- solve
- performance
- cocos2d
- Guide
- Show
- 4K
- Slow
- 50
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함