티스토리 뷰

HelloWorldScene.h

  1. #ifndef __HELLOWORLD_SCENE_H__
  2. #define __HELLOWORLD_SCENE_H__
  3.  
  4. #include "cocos2d.h"
  5. #include "cocostudio/CocoStudio.h"
  6. #include "ui\UIEditBox\UIEditBox.h"
  7. #include "ui/CocosGUI.h"
  8.  
  9. USING_NS_CC;
  10. using namespace ui;
  11.  
  12. class HelloWorld : public cocos2d::Layer, EditBoxDelegate
  13. {
  14. public:
  15. // there's no 'id' in cpp, so we recommend returning the class instance pointer
  16. static cocos2d::Scene* createScene();
  17.  
  18. // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
  19. virtual bool init();
  20.  
  21. // a selector callback
  22. void menuCloseCallback(cocos2d::Ref* pSender);
  23.  
  24. // implement the "static create()" method manually
  25. CREATE_FUNC(HelloWorld);
  26.  
  27. EditBox* eb_first; //First EditBox
  28. EditBox* eb_second; //Second EditBox
  29.  
  30. void editbox_Callback(EditBox* editBox); //Custom Function
  31.  
  32. virtual void editBoxEditingDidBegin(EditBox* editBox);
  33. virtual void editBoxEditingDidEnd(EditBox* editBox);
  34. virtual void editBoxTextChanged(EditBox* editBox, const std::string& text);
  35. virtual void editBoxReturn(EditBox* editBox);
  36. };
  37.  
  38. #endif // __HELLOWORLD_SCENE_H__
  39.  


HelloWorldScene.cpp

  1. #include "HelloWorldScene.h"
  2.  
  3. Scene* HelloWorld::createScene()
  4. {
  5. // 'scene' is an autorelease object
  6. auto scene = Scene::create();
  7.  
  8. // 'layer' is an autorelease object
  9. auto layer = HelloWorld::create();
  10.  
  11. // add layer as a child to scene
  12. scene->addChild(layer);
  13.  
  14. // return the scene
  15. return scene;
  16. }
  17.  
  18. // on "init" you need to initialize your instance
  19. bool HelloWorld::init()
  20. {
  21. //////////////////////////////
  22. // 1. super init first
  23. if ( !Layer::init() )
  24. {
  25. return false;
  26. }
  27.  
  28. auto rootNode = CSLoader::createNode("HelooWorldScene.csb");
  29. addChild(rootNode);
  30.  
  31. ///////////////////////////////////////First EditBox///////////////////////////////////////
  32. eb_first = EditBox::create(Size(150, 50), Scale9Sprite::create("YourPic.png"));
  33. eb_first->setAnchorPoint(Vec2(0, 0.5f));
  34. eb_first->setPosition(Vec2(50, 100));
  35. eb_first->setReturnType(ui::EditBox::KeyboardReturnType::NEXT); //Return Button Change(Next)
  36. eb_first->setDelegate(this);
  37. addChild(eb_first);
  38. ///////////////////////////////////////////////////////////////////////////////////////////////
  39. ///////////////////////////////////////Second EditBox///////////////////////////////////////
  40. eb_second = EditBox::create(Size(150, 50), Scale9Sprite::create("YourPic.png"));
  41. eb_second->setAnchorPoint(Vec2(0, 0.5f));
  42. eb_second->setPosition(Vec2(250, 100));
  43. eb_second->setReturnType(ui::EditBox::KeyboardReturnType::DONE); //Return Button Change(Done)
  44. eb_second->setDelegate(this);
  45. addChild(eb_second);
  46. ///////////////////////////////////////////////////////////////////////////////////////////////
  47.  
  48. return true;
  49. }
  50.  
  51. void HelloWorld::editBoxEditingDidBegin(EditBox* editBox) {
  52. }
  53. void HelloWorld::editBoxEditingDidEnd(EditBox* editBox) {
  54. }
  55. void HelloWorld::editBoxTextChanged(EditBox* editBox, const std::string& text) {
  56. }
  57. void HelloWorld::editBoxReturn(EditBox* editBox) {
  58. //the function when touched Return button.
  59. if (editBox == eb_first) {
  60. CallFunc *runCallback = CallFunc::create(CC_CALLBACK_0(HelloWorld::editbox_Callback, this, eb_second));
  61. this->runAction(Sequence::create(DelayTime::create(0.15f), runCallback, nullptr));
  62.          //0.15 second Delay -> runCallback
  63. }
  64. }
  65. void HelloWorld::editbox_Callback(EditBox* editBox) {
  66. editBox->touchDownAction(editBox, Widget::TouchEventType::ENDED);
  67. //eb_second get focus and show keyboard like eb_second has touched.
  68. }

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
링크
«   2024/05   »
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 31
글 보관함