[cocos2d-x] TextInputTest(로그인 만들기)

2013. 6. 14. 10:42cocos2d-x



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

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

}