2013. 7. 12. 14:42ㆍcocos2d-x
로그인 에디트 박스가 이게 더 좋은것 같아서....바꾸는게 나을듯 하다..
비밀번호 *** 표시가 있더라....
이미지는 아무거나 사용하시길..
// 헤더 - - - - - - - - - - - - - - - - - -
#ifndef __Login_H__
#define __Login_H__
#include "cocos2d.h"
#include "cocos-ext.h"
class KeyboardNotificationLayer;
using namespace cocos2d;
using namespace extension;
using namespace std;
class Login : public CCLayer, public cocos2d::extension::CCEditBoxDelegate
{
public:
virtual bool init();
static CCScene* scene();
CCSize winSize;
//멀티레이어를 위한 objc
CREATE_FUNC(Login);
CCTextFieldTTF *ID_Field;
string id_R; //진짜 아이디가 담길 곳
string password_R; //진짜 비밀번호가 담길 곳
//터치
void ccTouchesBegan(cocos2d::CCSet* pTouch, cocos2d::CCEvent* pEvent);
void keyBackClicked(); //종료키
void Login_request(CCObject* pSender);
void onHttpRequestCompleted(CCNode *sender, void *data);
virtual void editBoxEditingDidBegin(cocos2d::extension::CCEditBox* editBox);
virtual void editBoxEditingDidEnd(cocos2d::extension::CCEditBox* editBox);
virtual void editBoxTextChanged(cocos2d::extension::CCEditBox* editBox, const std::string& text);
virtual void editBoxReturn(cocos2d::extension::CCEditBox* editBox);
private:
cocos2d::CCLabelTTF* m_pTTFShowEditReturn;
cocos2d::extension::CCEditBox* m_pEditName;
cocos2d::extension::CCEditBox* m_pEditPassword;
};
#endif
//cpp - - - - - - - - - - - -
#include "Login.h"
#include "SimpleAudioEngine.h"
#include "rapidjson/document.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "cocos-ext.h"
using namespace cocos2d;
using namespace CocosDenshion;
using namespace extension;
using namespace std;
size_t func( void* ptr, size_t size, size_t nmemb, void* stream)
{
strncat( (char*)stream, (char*)ptr, size*nmemb);
return size*nmemb;
}
CCScene* Login::scene()
{
CCScene *scene = CCScene::create();
Login *layer = Login::create();
scene->addChild(layer);
return scene;
}
bool Login::init()
{
if (!CCLayer::init()) {
return false;
}
Appd->soundPlay();
winSize = CCDirector::sharedDirector()->getWinSize(); //화면 사이즈
this->setTouchEnabled(true); //터치 가능(cocos2d-x)
CCPoint visibleOrigin = CCEGLView::sharedOpenGLView()->getVisibleOrigin();
CCSize visibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize();
CCSize editBoxSize = CCSizeMake(visibleSize.width - winSize.width/2, 60);
//editbox
{
//아이디
m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("orange_edit.png"));
m_pEditName->setPosition(ccp(visibleOrigin.x+visibleSize.width/2 -30, visibleOrigin.y+visibleSize.height/2 + 50));
m_pEditName->setFontName("Arial");
m_pEditName->setFontSize(40);
m_pEditName->setFontColor(ccGREEN);
m_pEditName->setPlaceHolder("아이디:");
m_pEditName->setPlaceholderFontColor(ccGREEN);
m_pEditName->setMaxLength(8);
m_pEditName->setReturnType(kKeyboardReturnTypeDone);
// m_pEditPassword->setInputFlag(kEditBoxInputFlagSensitive);
// m_pEditPassword->setInputMode(kEditBoxInputModeAny);
m_pEditName->setDelegate(this);
addChild(m_pEditName, 2);
//비밀번호
// middle
m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("orange_edit.png"));
m_pEditPassword->setPosition(ccp(visibleOrigin.x+visibleSize.width/2 -30, visibleOrigin.y+visibleSize.height/2-50));
m_pEditPassword->setFont("Arial", 40);
m_pEditPassword->setFontColor(ccGREEN);
m_pEditPassword->setPlaceholderFontColor(ccGREEN);
m_pEditPassword->setPlaceHolder("Password:");
m_pEditPassword->setMaxLength(13);
m_pEditPassword->setInputFlag(kEditBoxInputFlagPassword);
m_pEditPassword->setInputMode(kEditBoxInputModeSingleLine);
m_pEditPassword->setDelegate(this);
addChild(m_pEditPassword);
}
//로그인 버튼 이미지
{
CCSprite *login_btn = CCSprite::create("login_btn.png");
login_btn->setPosition(ccp(winSize.width/2+400, winSize.height/2));
login_btn->setScale(winSize.width/11/login_btn->getContentSize().width);
login_btn->setTag(001);
this->addChild(login_btn, 3);
}
//회원가입 버튼
{
CCSprite *join_btn = CCSprite::create("Member_Join.png");
join_btn->setPosition(ccp(winSize.width/2, winSize.height/2-150));
join_btn->setTag(002);
this->addChild(join_btn, 3);
}
return true;
}
void Login::editBoxEditingDidBegin(cocos2d::extension::CCEditBox* editBox) {
// CCLog("editBox %p DidBegin !", editBox);
}
void Login::editBoxEditingDidEnd(cocos2d::extension::CCEditBox* editBox) {
// CCLog("editBox %p DidEnd !", editBox);
}
void Login::editBoxTextChanged(cocos2d::extension::CCEditBox* editBox, const std::string& text) {
// CCLog("editBox %p TextChanged, text: %s ", editBox, text.c_str());
}
void Login::editBoxReturn(CCEditBox* editBox) {
// CCLog("editBox %p was returned !");
if (m_pEditName == editBox)
{
// m_pTTFShowEditReturn->setString("Name EditBox return !");
}
// else if (m_pEditPassword == editBox)
// {
// m_pTTFShowEditReturn->setString("Password EditBox return !");
// }
}
#pragma mark - 터치
void Login::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent){
CCTouch *pTouch = (CCTouch *)pTouches->anyObject();
CCPoint point = pTouch->getLocationInView();
point = CCDirector::sharedDirector()->convertToGL(point);
string a = "123";
CCSprite *login_btn = (CCSprite*)this->getChildByTag(001);
CCRect login_rect = login_btn->boundingBox();
if (login_rect.containsPoint(point)) {
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.2, select::scene(), ccc3(255,255,255)));
}
cout << id_R << endl;
cout << password_R << endl;
}
void Login::keyBackClicked() {
#pragma mark - 안드로이드 종료 버튼시 어플 종료
CCDirector::sharedDirector()->end();
}
'cocos2d-x' 카테고리의 다른 글
[cocos2d-x]CCLabelTTF, Font 사용법 (0) | 2013.07.24 |
---|---|
[cocos2d-x]프로그레스 바 사용하기! (0) | 2013.07.15 |
[cocos2d-x] TextInputTest(로그인 만들기) (0) | 2013.06.14 |
[cocos2d-x] ssl !! (0) | 2013.06.07 |
[android]cocos2d-x 다운로드! 안드로이드 편 (0) | 2013.06.04 |