[10] coco2d-x CCTextFieldTTF the simplest way to achieve password login "*"

Source: Internet
Author: User

The simplest method is to use CCTextFieldTTF to set the graph password,

First, the class inheritance relationship

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

There are several methods

// CCTextFieldDelegatevirtual 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);


Add the following code to the 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 ());

In this way, each input character changes the previous character to "*".

After receiving the input, the bool Login: onTextFieldDetachWithIME (CCTextFieldTTF * pSender) Method

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

In this way, all are displayed as "*".

Note that here pSender-> m_pInputText; an error is reported. Go to CCTextFieldTTF. h and set m_pInputText to public!


This method may be faulty! Because the framework source code has been modified! But I haven't found it yet! I am also studying. I hope you will pay attention to the discussion if you find any problems!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.