티스토리 뷰
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; //첫번째 에디트박스 EditBox* eb_second; //두번째 에디트박스 void editbox_Callback(EditBox* editBox); //콜백받으면 실행될 임의 함수 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); ///////////////////////////////////////첫번째 에디트박스/////////////////////////////////////// eb_first = EditBox::create(Size(150, 50), Scale9Sprite::create("임의.png")); //에디트박스 생성 eb_first->setAnchorPoint(Vec2(0, 0.5f)); //중심점을 좌측 중앙으로 설정 eb_first->setPosition(Vec2(50, 100)); //위치설정 eb_first->setReturnType(ui::EditBox::KeyboardReturnType::NEXT); //search버튼을 다음버튼으로 표시 eb_first->setDelegate(this); addChild(eb_first); //에디트박스를 rootNode의 차일드로 추가 /////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////두번째 에디트박스/////////////////////////////////////// eb_second = EditBox::create(Size(150, 50), Scale9Sprite::create("임의.png")); //에디트박스 생성 eb_second->setAnchorPoint(Vec2(0, 0.5f)); //중심점을 좌측 중앙으로 설정 eb_second->setPosition(Vec2(250, 100)); //위치설정 eb_second->setReturnType(ui::EditBox::KeyboardReturnType::DONE); //search버튼을 완료버튼으로 표시 eb_second->setDelegate(this); addChild(eb_second); //에디트박스를 rootNode의 차일드로 추가 /////////////////////////////////////////////////////////////////////////////////////////////// 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) { //에디트 박스에서 리턴 키를 입력할 때 출력되는 메소드 //일반적으로 editBoxEditingDidEnd() 호출후에 호출된다. if (editBox == eb_first) { //리턴키를 누른 에디트박스가 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초의 딜레이 후->runCallback함수실행 } } void HelloWorld::editbox_Callback(EditBox* editBox) { //콜백함수 editBox->touchDownAction(editBox, Widget::TouchEventType::ENDED); //eb_second가 터치된것처럼 포커스를 얻고 키보드가 나타남 }
에디트박스를 2개 만들어서
첫 에디트박스의 입력이 끝나면 자동으로 두번째 에디트박스로
이동되고 키보드가 나오게 하는 코드입니다.
딜레이를 넣지않으면 키보드가 안뜨거나
커서가 정신을 못차리고 왔다갔다하는 버그가 발생합니다.
'프로그래밍 > cocos2d-x' 카테고리의 다른 글
Cocos2d-x OpenSSL 앱 제출이 거부, 해결법 직빵! (7) | 2016.08.28 |
---|---|
구글플레이 개발자 등록하기! (수수료$25) (0) | 2016.07.21 |
cocos2d-x. 안드로이드 포팅 시 낮은 FPS 해결법 (1) | 2016.02.15 |
Tiled Map Editor의 "Add Image Layer"는 사용하지말자! (0) | 2016.01.20 |
cocos2d-x 샘플 예제(ccp-tests) 실행 및 코드 참고하기 (0) | 2015.04.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- cocos2d-x
- 1지구
- 티스토리
- 탐험가연맹
- 후기
- 포켓몬
- 검은바위 산
- 4지구
- 에라오브엠파이어
- 공략
- 스위스
- 솔직
- 보상
- 솔직후기
- 목록
- 고
- EOE
- cocos2d
- 방법
- 어떻게
- 카라잔
- 2지구
- 하는법
- go
- 포켓몬고
- 하스스톤
- 한눈에
- 포켓몬go
- 3지구
- 카드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함