2013. 6. 14. 10:42ㆍcocos2d-x
Login.h +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#ifndef __Login_H__
#define __Login_H__
#include "cocos2d.h"
#include "VisibleRect.h"
class KeyboardNotificationLayer;
using namespace cocos2d;
using namespace std;
class Login : public CCLayer, public CCIMEDelegate
{
public:
virtual bool init();
static CCScene* scene();
CCSize winSize;
CREATE_FUNC(Login);
void keyboardWillShow(CCIMEKeyboardNotificationInfo &info);
void keyboardWillHide(CCIMEKeyboardNotificationInfo &info);
//터치
void ccTouchesBegan(cocos2d::CCSet* pTouch, cocos2d::CCEvent* pEvent);
// //드래그
// void ccTouchesMoved(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);
// //터치 업(손가락을 뗐을때
// void ccTouchesEnded(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);
// //터치 exception
// void ccTouchesCancelled(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent);
void keyBackClicked();
};
#endif
Login.cpp+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "Login.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* Login::scene()
{
CCScene *scene = CCScene::create();
Login *layer = Login::create();
scene->addChild(layer);
return scene;
}
bool Login::init()
{
if ( !CCLayer::init() )
{
return false;
}
winSize = CCDirector::sharedDirector()->getWinSize();
this->setTouchEnabled(true);
CCTextFieldTTF *textfield = CCTextFieldTTF::textFieldWithPlaceHolder("ID를 입력해주세요.", CCSize(480,40), kCCTextAlignmentCenter, "Arial", 30);
textfield->setAnchorPoint(CCPointZero);
textfield->setPosition(ccp(0,500));
textfield->setTag(100);
this->addChild(textfield);
CCLabelTTF *label = CCLabelTTF::create("ID : ", "", 50);
label->setPosition(ccp(240,100));
label->setTag(200);
this->addChild(label);
return true;
}
void Login::keyboardWillShow(CCIMEKeyboardNotificationInfo &info)
{
CCLOG("keyboardWillShow");
CCTextFieldTTF *textfield = (CCTextFieldTTF *)this->getChildByTag(100);
textfield->setString("");
}
void Login::keyboardWillHide(CCIMEKeyboardNotificationInfo &info)
{
CCLog("keyboardWillHide");
CCTextFieldTTF *textfield = (CCTextFieldTTF *)this->getChildByTag(100);
CCLabelTTF *label = (CCLabelTTF *)this->getChildByTag(200);
label->setString(textfield->getString());
}
void Login::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCTouch *pTouch = (CCTouch *)pTouches->anyObject();
CCPoint point = pTouch->getLocationInView();
point = CCDirector::sharedDirector()->convertToGL(point);
CCTextFieldTTF *textfield = (CCTextFieldTTF *)this->getChildByTag(100);
CCRect rect = textfield->boundingBox();
CCLog("s");
if(rect.containsPoint(point)) {
textfield->attachWithIME();
}
}
void Login::keyBackClicked() {
#pragma mark - 안드로이드 종료 버튼시 어플 종료
CCDirector::sharedDirector()->end();
}
'cocos2d-x' 카테고리의 다른 글
[cocos2d-x]프로그레스 바 사용하기! (0) | 2013.07.15 |
---|---|
[cocos2d-x] 로그인 (에디트 박스 사용) (0) | 2013.07.12 |
[cocos2d-x] ssl !! (0) | 2013.06.07 |
[android]cocos2d-x 다운로드! 안드로이드 편 (0) | 2013.06.04 |
[cocos2d-x]CURL 파일 download ! (0) | 2013.06.03 |