欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

Cocos2d-x中CCEditBox文本輸入框的使用實(shí)例

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點(diǎn)擊: 次

文本輸入框這個東西相信大家不論做什么游戲總會用到吧,今天我們就來看看這個東西如何使用。文本輸入框同樣屬于擴(kuò)展庫中的內(nèi)容,所以你知道怎么做了吧。當(dāng)用戶要在文本框中輸入內(nèi)容,這一系列的過程我們需要一些函數(shù)的調(diào)用來獲得我們想要的東西,包含這些函數(shù)的類需要實(shí)現(xiàn)CCEditBoxDelegate這個接口,下面我們來看看具體如何使用吧。

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
//需要包含擴(kuò)展庫
#include "cocos-ext.h"
using namespace cocos2d;
using namespace cocos2d::extension;
//使用CCEditBox必須繼承自CCEditBoxDelegate接口,實(shí)現(xiàn)其的一些函數(shù)
class HelloWorld : public cocos2d::CCLayer,public CCEditBoxDelegate
{
public:
  // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
  virtual bool init();

  // there's no 'id' in cpp, so we recommend returning the class instance pointer
  static cocos2d::CCScene* scene();

  // implement the "static node()" method manually
  CREATE_FUNC(HelloWorld);

	//要實(shí)現(xiàn)的函數(shù)如下
	//當(dāng)鍵盤彈出編輯框獲得焦點(diǎn)時調(diào)用

	virtual void editBoxEditingDidBegin(CCEditBox* editBox);

	//當(dāng)鍵盤消失編輯框失去焦點(diǎn)時調(diào)用

	virtual void editBoxEditingDidEnd(CCEditBox* editBox);

	//當(dāng)編輯框文本改變時調(diào)用

	virtual void editBoxTextChanged(CCEditBox* editBox, const std::string& text);

	//當(dāng)返回鍵按下時或者點(diǎn)擊了鍵盤以外的區(qū)域時調(diào)用

	virtual void editBoxReturn(CCEditBox* editBox);

private:
	CCSize m_size;
	CCEditBox * editBox;
};

#endif // __HELLOWORLD_SCENE_H__
bool HelloWorld::init()
{
  //////////////////////////////
  // 1. super init first
  if ( !CCLayer::init() )
  {
    return false;
  }

	this->m_size = CCDirector::sharedDirector()->getVisibleSize();

	//第一個參數(shù)是文本框的大小,第二個是文本框在正常情況下的背景圖片,第三個參數(shù)是按下時候的背景圖片
	//第四個參數(shù)是不可用的時候的背景圖片,后三個參數(shù)可以省略
	editBox = CCEditBox::create(CCSize(300,40),
		CCScale9Sprite::create("9.9.png"),
		CCScale9Sprite::create("8.9.png"));
	editBox->setPosition(ccp(m_size.width/2,m_size.height/2));
	this->addChild(editBox);
	//設(shè)置預(yù)置文本
	editBox->setPlaceHolder("please input:");

	//設(shè)置文本字體的顏色

	editBox->setFontColor(ccc3(255,0,0));

	//設(shè)置最大長度 ,按說這個地方是輸入框文字的長度,但是在win32上不管用,移植到android的時候是管用的

	editBox->setMaxLength(1);

	//setInputMode()設(shè)置輸入類型,可以包括如下的幾種
	//   kEditBoxInputModeAny:     開啟任何文本的輸入鍵盤,包括換行

	//   kEditBoxInputModeEmailAddr:  開啟 郵件地址 輸入類型鍵盤

	//   kEditBoxInputModeNumeric:   開啟 數(shù)字符號 輸入類型鍵盤

	//   kEditBoxInputModePhoneNumber: 開啟 電話號碼 輸入類型鍵盤

	//   kEditBoxInputModeUrl:     開啟 URL 輸入類型鍵盤

	//   kEditBoxInputModeDecimal:   開啟 數(shù)字 輸入類型鍵盤,允許小數(shù)點(diǎn)

	//   kEditBoxInputModeSingleLine: 開啟任何文本的輸入鍵盤,不包括換行
	editBox->setInputMode(kEditBoxInputModeAny);

	//設(shè)置輸入標(biāo)志,可以有如下的幾種
	//kEditBoxInputFlagPassword:        密碼形式輸入

	//kEditBoxInputFlagSensitive:        敏感數(shù)據(jù)輸入、存儲輸入方案且預(yù)測自動完成

	//kEditBoxInputFlagInitialCapsWord:     每個單詞首字母大寫,并且伴有提示

	//kEditBoxInputFlagInitialCapsSentence:   第一句首字母大寫,并且伴有提示

	//kEditBoxInputFlagInitialCapsAllCharacters:所有字符自動大寫
	editBox->setInputFlag(kEditBoxInputFlagPassword);

	//設(shè)置鍵盤中return鍵顯示的字符,這個移植android的時候沒有看出來

  editBox->setReturnType(kKeyboardReturnTypeGo);

  //包括這些選項(xiàng)

  //kKeyboardReturnTypeDefault: 默認(rèn)使用鍵盤return 類型

	//kKeyboardReturnTypeDone:   默認(rèn)使用鍵盤return類型為“Done”字樣

	//kKeyboardReturnTypeSend:   默認(rèn)使用鍵盤return類型為“Send”字樣

	//kKeyboardReturnTypeSearch:  默認(rèn)使用鍵盤return類型為“Search”字樣

	//kKeyboardReturnTypeGo:    默認(rèn)使用鍵盤return類型為“Go”字樣

	//寫上這句話的時候以下的四個函數(shù)才會被調(diào)用
	editBox->setDelegate(this);
  return true;
}

//實(shí)現(xiàn)以下的函數(shù),觀察他們是何時被調(diào)用的
void HelloWorld::editBoxEditingDidBegin(CCEditBox * editBox)
{
	CCLog("begin!");
	CCLabelTTF * ttf = CCLabelTTF::create("begin","",24);
	ttf->setPosition(ccp(m_size.width/4,m_size.height*1/5));
	this->addChild(ttf);
}

void HelloWorld::editBoxEditingDidEnd(CCEditBox * editBox)
{
	CCLog("end!");
	CCLabelTTF * ttf = CCLabelTTF::create("end","",24);
	ttf->setPosition(ccp(m_size.width/4,m_size.height*4/5));
	this->addChild(ttf);
}

void HelloWorld::editBoxTextChanged(CCEditBox * editBox,const std::string & text)
{
	CCLog("textChanged!");
	CCLabelTTF * ttf = CCLabelTTF::create("textChanged!","",24);
	ttf->setPosition(ccp(m_size.width/4,m_size.height*3/5));
	this->addChild(ttf);
}

void HelloWorld::editBoxReturn(CCEditBox * editBox)
{
	CCLog("return");
	CCLabelTTF * ttf = CCLabelTTF::create("return","",24);
	ttf->setPosition(ccp(m_size.width/4,m_size.height*2/5));
	this->addChild(ttf);

	char * str = (char *)this->editBox->getText();
	CCLabelTTF * text = CCLabelTTF::create(str,"",24);
	text->setPosition(ccp(m_size.width/2,m_size.height*2/5));
	this->addChild(text);
}

上一篇:Cocos2d-x UI開發(fā)之菜單類使用實(shí)例

欄    目:C語言

下一篇:Cocos2d-x Schedule定時器的使用實(shí)例

本文標(biāo)題:Cocos2d-x中CCEditBox文本輸入框的使用實(shí)例

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3379.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有