coco2d-x CCTextFieldTTF最简单的方法实现密码登陆“*”

来源:未知 责任编辑:责任编辑 发表时间:2014-01-06 18:19 点击:

最简单的方法使用CCTextFieldTTF设置图密码框,

首先类的继承关系

 

class Login:public cocos2d::CCLayer,CCIMEDelegate,CCTextFieldDelegate

最有是这几个方法

 

 

	// CCTextFieldDelegate
	virtual bool onTextFieldAttachWithIME(CCTextFieldTTF * pSender);
	virtual bool onTextFieldDetachWithIME(CCTextFieldTTF * pSender);
	virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);
	virtual bool onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen);
	virtual bool onDraw(CCTextFieldTTF * pSender);


 

先在这个bool Login::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)方向里加入以下代码

int count=((pSender->getCharCount())>0?(pSender->getCharCount()):1);
if (count<=0)
{
count=1;
}
std::string paSt(count,'*');
pSender->setString(paSt.c_str());

这样,每输入一个字符,上一个字符就变成了“*”

输入接收后,这这个bool Login::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)方法里

std::string pstr=pSender->getPlaceHolder();
if (pstr=="password...")
{
std::string *inpstr=pSender->m_pInputText;
std::string showstr(inpstr->c_str(),0,inpstr->length()-1);
pSender->setString(showstr.c_str());
}

这样就全部显示成了“*”

注意这里pSender->m_pInputText;会报错了,进入CCTextFieldTTF.h,将m_pInputText该成public的就OK了!

 

本方法也许会有问题!因为修改了框架源码!但是我暂时没有发现!本人也在学习中,发现问题的希望大家留意讨论!

 

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • cocos2d-x学习笔记(19)--label 、label atlas
    • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
    • Cocos2d-x学习(一):HelloWorld
    • cocos2dx在xcode下开发,编译到android上(2)
    • cocos2d 设置屏幕默认方向
    • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
    • Cocos2d-x 2.0 之 Actions “三板斧” 之一
    • cocos2d-x学习笔记(18)--游戏打包(windows平台)
    • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1